UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

115 lines 5.5 kB
"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 test_utils_1 = require("@sprucelabs/test-utils"); const CommandService_1 = __importDefault(require("../../../services/CommandService")); const LintService_1 = __importDefault(require("../../../services/LintService")); const AbstractCliTest_1 = __importDefault(require("../../../tests/AbstractCliTest")); class LintServiceTest extends AbstractCliTest_1.default { static wasFixInvoked = false; static async beforeEach() { await super.beforeEach(); LintService_1.default.enableLinting(); this.wasFixInvoked = false; this.commandFaker.on(/node/, () => { this.wasFixInvoked = true; }); } static async throwsWhenLintReturnsMessage() { await this.FeatureFixture().installCachedFeatures('skills'); CommandService_1.default.fakeCommand(/node/, { code: 0, stdout: `[{"filePath":"/Users/taylorromero/Development/SpruceLabs/spruce-appointments-skill/src/.spruce/stores/stores.types.ts","messages":[{"fatal":false,"severity":1,"message":"File ignored by default. Use a negated ignore pattern (like \\"--ignore-pattern '!<relative/path/to/filename>'\\") to override."}],"errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":[]}]\n`, }); await test_utils_1.assert.doesThrowAsync(() => this.Service('lint').fix('./go')); } static async worksWhenNoMessagesReturned() { await this.FeatureFixture().installCachedFeatures('skills'); CommandService_1.default.fakeCommand(/node/, { code: 0, stdout: `[{"filePath":"/Users/taylorromero/Development/SpruceLabs/spruce-appointments-skill/src/.spruce/stores/stores.types.ts","messages":[{"fatal":false,"severity":1,"message":"File ignored by default. Use a negated ignore pattern (like \\"--ignore-pattern '!<relative/path/to/filename>'\\") to override."}],"errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"usedDeprecatedRules":[]}]\n`, }); await this.fix('./go'); } static async defaultIgnore() { test_utils_1.assert.isEqualDeep(LintService_1.default.ignorePatterns, [ 'valueType.tmp', '.md', '.js', '.gitignore', '.mjs', '.spruce', '.nvmrc', 'tsconfig.json', '.npmignore', ]); } static async willIgnoreFirstItemInIgnoreList() { const pattern = (0, test_utils_1.generateId)(); this.setIgnorePatterns([pattern]); await this.fixAndAssertNotFixed(pattern); await this.fix('whatever.ts'); this.assertWasFixed(); } static async willIgnoreSecondItemInIgnoreList() { const pattern = (0, test_utils_1.generateId)(); this.setIgnorePatterns(['whatever.ts', pattern]); await this.fixAndAssertNotFixed(pattern); } static async ignoresPartialMatch() { const pattern = (0, test_utils_1.generateId)(); this.setIgnorePatterns([pattern + '/whatever.ts']); await this.fixAndAssertNotFixed('whatever.ts'); } static async partialMatchesOtherWay() { this.setIgnorePatterns(['valueType.tmp']); await this.fixAndAssertNotFixed(this.resolvePath('valueType.tmp')); } static async fixAndAssertNotFixed(pattern) { await this.fix(pattern); this.assertWasNotFixed(); } static assertWasFixed() { test_utils_1.assert.isTrue(this.wasFixInvoked, 'Fix was not invoked when it should have been.'); } static assertWasNotFixed() { test_utils_1.assert.isFalse(this.wasFixInvoked, `Fix was invoked when it should not have been.`); } static setIgnorePatterns(patterns) { LintService_1.default.ignorePatterns = patterns; } static async fix(pattern) { await this.Service('lint').fix(pattern); } } exports.default = LintServiceTest; __decorate([ test_utils_1.test.skip('new way of linting never seems to throw') ], LintServiceTest, "throwsWhenLintReturnsMessage", null); __decorate([ (0, test_utils_1.test)() ], LintServiceTest, "worksWhenNoMessagesReturned", null); __decorate([ (0, test_utils_1.test)() ], LintServiceTest, "defaultIgnore", null); __decorate([ (0, test_utils_1.test)() ], LintServiceTest, "willIgnoreFirstItemInIgnoreList", null); __decorate([ (0, test_utils_1.test)() ], LintServiceTest, "willIgnoreSecondItemInIgnoreList", null); __decorate([ (0, test_utils_1.test)() ], LintServiceTest, "ignoresPartialMatch", null); __decorate([ (0, test_utils_1.test)() ], LintServiceTest, "partialMatchesOtherWay", null); //# sourceMappingURL=LintService.test.js.map