@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
154 lines • 6.65 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
const test_utils_1 = require("@sprucelabs/test-utils");
const test_utils_2 = require("@sprucelabs/test-utils");
const TestRunner_1 = __importDefault(require("../../features/test/TestRunner"));
const LintService_1 = __importDefault(require("../../services/LintService"));
const AbstractTestTest_1 = __importDefault(require("../../tests/AbstractTestTest"));
class TestRunnerTest extends AbstractTestTest_1.default {
static testRunner;
static hasCreatedTest;
static async beforeEach() {
await super.beforeEach();
this.hasCreatedTest = false;
LintService_1.default.enableLinting();
this.testRunner = new TestRunner_1.default({
cwd: this.cwd,
commandService: this.Service('command'),
});
}
static async canCreateTestRunner() {
test_utils_1.assert.isTruthy(this.testRunner);
}
static async runningOnDirWithNoTestsConfiguredThrows() {
const err = await test_utils_1.assert.doesThrowAsync(() => this.testRunner.run());
test_utils_2.errorAssert.assertError(err, 'INVALID_TEST_DIRECTORY', {
dir: this.cwd,
});
}
static async getsFailedResultsWhenTestFails() {
const cli = await this.installTests();
await this.createTest({ cli, name: 'Can book appointment' });
let results = await this.testRunner.run();
test_utils_1.assert.isEqual(results.totalTestFiles, 1);
test_utils_1.assert.isEqual(results.totalFailed, 1);
test_utils_1.assert.isEqual(results.totalTests, 2);
await this.createTest({ cli, name: 'Can cancel appointment' });
results = await this.testRunner.run();
test_utils_1.assert.isEqual(results.totalTestFiles, 2);
test_utils_1.assert.isEqual(results.totalFailed, 2);
test_utils_1.assert.isEqual(results.totalTests, 4);
}
static async passesOnGoodTests() {
const cli = await this.installTests();
await this.createTest({ cli, name: 'Can pass tests', shouldFix: true });
const testResults = await this.testRunner.run();
test_utils_1.assert.isEqual(testResults.totalTestFiles, 1);
test_utils_1.assert.isEqual(testResults.totalFailed, 0);
test_utils_1.assert.isEqual(testResults.totalPassed, 2);
test_utils_1.assert.isEqual(testResults.totalTests, 2);
}
static async emitsEventsOnTestUpdates() {
const cli = await this.installTests();
let results;
await this.testRunner.on('did-update', (payload) => {
results = payload.results;
});
await this.createTest({ cli, name: 'Emitting test' });
await this.testRunner.run();
test_utils_1.assert.isTruthy(results);
test_utils_1.assert.isEqual(results.totalTestFiles, 1);
test_utils_1.assert.isEqual(results.totalFailed, 1);
test_utils_1.assert.isEqual(results.totalTests, 2);
}
static async canHandlePattern() {
const cli = await this.installTests();
await this.createTest({
cli,
name: 'Can handlePatterns tests',
shouldBuild: false,
});
await this.createTest({ cli, name: 'Can handlePatterns2 tests' });
const results = await this.testRunner.run({
pattern: 'canHandlePatternsTests',
});
test_utils_1.assert.isTruthy(results);
test_utils_1.assert.isEqual(results.totalTestFiles, 1);
test_utils_1.assert.isEqual(results.totalFailed, 1);
test_utils_1.assert.isEqual(results.totalTests, 2);
}
static async testsCanBeKilled() {
const cli = await this.installTests();
await this.createTest({
cli,
name: 'Can handlePatterns tests',
shouldBuild: false,
});
await this.createTest({ cli, name: 'Can handlePatterns2 tests' });
const promise = this.testRunner.run({
pattern: 'canHandlePatternsTests',
});
this.testRunner.kill();
const results = await promise;
test_utils_1.assert.isTrue(results.wasKilled);
}
static async createTest(options) {
const { name, shouldFix = false, shouldBuild = true } = options;
const promise = this.Action('test', 'create').execute({
type: 'behavioral',
nameReadable: name,
nameCamel: spruce_skill_utils_1.namesUtil.toCamel(name),
namePascal: spruce_skill_utils_1.namesUtil.toPascal(name),
});
await this.waitForInput();
if (this.hasCreatedTest) {
await this.ui.sendInput('');
await this.waitForInput();
}
this.hasCreatedTest = true;
await this.ui.sendInput('');
const results = await promise;
if (shouldFix) {
const file = results.files?.[0];
test_utils_1.assert.isTruthy(file);
this.fixBadTest(file.path);
}
if (shouldBuild) {
await this.Service('build').build();
}
return results;
}
}
exports.default = TestRunnerTest;
__decorate([
(0, test_utils_1.test)()
], TestRunnerTest, "canCreateTestRunner", null);
__decorate([
(0, test_utils_1.test)()
], TestRunnerTest, "runningOnDirWithNoTestsConfiguredThrows", null);
__decorate([
(0, test_utils_1.test)()
], TestRunnerTest, "getsFailedResultsWhenTestFails", null);
__decorate([
(0, test_utils_1.test)()
], TestRunnerTest, "passesOnGoodTests", null);
__decorate([
(0, test_utils_1.test)()
], TestRunnerTest, "emitsEventsOnTestUpdates", null);
__decorate([
(0, test_utils_1.test)()
], TestRunnerTest, "canHandlePattern", null);
__decorate([
(0, test_utils_1.test)()
], TestRunnerTest, "testsCanBeKilled", null);
//# sourceMappingURL=TestRunner.test.js.map