@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
145 lines • 6.75 kB
JavaScript
;
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 CommandService_1 = __importDefault(require("../../../services/CommandService"));
const AbstractCliTest_1 = __importDefault(require("../../../tests/AbstractCliTest"));
const uiAssert_utility_1 = __importDefault(require("../../../tests/utilities/uiAssert.utility"));
class UpgradingANodeModuleTest extends AbstractCliTest_1.default {
static pkg;
static async beforeEach() {
await super.beforeEach();
await this.FeatureFixture().installCachedFeatures('everythingInNode');
this.pkg = this.Service('pkg');
const featureInstaller = this.featureInstaller;
featureInstaller.markAsPermanentlySkipped('skill');
}
static async buildErrorsGetPassedThroughToResults() {
CommandService_1.default.fakeCommand(/yarn (add|install)/gis, { code: 0 });
CommandService_1.default.fakeCommand(/yarn clean.build/gis, { code: 1 });
CommandService_1.default.fakeCommand(/yarn build.dev/gis, { code: 0 });
await this.emitter.on('feature.did-execute', () => {
return {
errors: undefined,
};
});
const results = await this.Action('node', 'upgrade').execute({});
test_utils_1.assert.isTruthy(results.errors);
}
static async upgradingWritesExpectedFiles() {
CommandService_1.default.fakeCommand(/build/gis, { code: 0 });
const shouldNotBeFound = [
'src/.spruce/skill.ts',
'src/.spruce/features',
];
spruce_skill_utils_1.diskUtil.deleteDir(this.resolveHashSprucePath('features'));
const results = await this.upgrade();
test_utils_1.assert.isFalsy(results.errors);
for (const search of shouldNotBeFound) {
const doesExist = spruce_skill_utils_1.diskUtil.doesFileExist(this.resolvePath(search));
test_utils_1.assert.isFalse(doesExist, `Should not have found ${search}`);
}
}
static async shouldReWriteNodeDirsAndSkipIndex() {
for (const file of ['tsconfig.json', 'src/index.ts']) {
const tsConfig = this.resolvePath(file);
spruce_skill_utils_1.diskUtil.writeFile(tsConfig, 'beenChanged');
}
this.fakeYarn();
const promise = this.upgrade();
await uiAssert_utility_1.default.assertRendersConfirmWriteFile(this.ui);
test_utils_1.assert.isEqual(spruce_skill_utils_1.diskUtil.readFile(this.resolvePath('src/index.ts')), 'beenChanged');
await promise;
}
static async resolvePathAliasesIsADevDependencyInNodeModules() {
this.assertResolvePathAliasesIsDevDependency();
await this.upgrade();
this.assertResolvePathAliasesIsDevDependency();
}
static async movesResolvePathAliasesToDevDependencyOnUpgrade() {
const version = this.pkg.get([
'devDependencies',
'@sprucelabs/resolve-path-aliases',
]);
this.pkg.unset(['devDependencies', '@sprucelabs/resolve-path-aliases']);
this.pkg.set({
path: ['dependencies', '@sprucelabs/resolve-path-aliases'],
value: version,
});
await this.upgrade();
this.assertResolvePathAliasesIsDevDependency();
}
static async removesBuildFromScriptsIfMatchesBrokenBuild() {
this.pkg.set({
path: ['scripts', 'build'],
value: 'yarn run build.tsc --sourceMap ; yarn run resolve-paths',
});
this.fakeYarn();
await this.upgrade();
const build = this.pkg.get(['scripts', 'build']);
test_utils_1.assert.isFalsy(build, 'Should not have build script since it matches broken build');
}
static async doesNotRemoveBuildFromScriptsIfDoesNotMatchBrokenBuild() {
const value = 'yarn run build.tsc --sourceMap';
this.pkg.set({
path: ['scripts', 'build'],
value,
});
this.fakeYarn();
await this.upgrade();
const build = this.pkg.get(['scripts', 'build']);
test_utils_1.assert.isEqual(build, value, 'Should have build script since it does not match broken build');
}
static fakeYarn() {
CommandService_1.default.fakeCommand(/yarn/gi, {
code: 0,
});
}
static assertResolvePathAliasesIsDevDependency() {
const devVersion = this.pkg.get([
'devDependencies',
'@sprucelabs/resolve-path-aliases',
]);
test_utils_1.assert.isTruthy(devVersion, 'Should have resolve path aliases as a dev dependency');
const prodVersion = this.pkg.get([
'dependencies',
'@sprucelabs/resolve-path-aliases',
]);
test_utils_1.assert.isFalsy(prodVersion, 'Should not have resolve path aliases as a prod dependency');
}
static async upgrade() {
return await this.Action('node', 'upgrade').execute({});
}
}
exports.default = UpgradingANodeModuleTest;
__decorate([
(0, test_utils_1.test)()
], UpgradingANodeModuleTest, "buildErrorsGetPassedThroughToResults", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingANodeModuleTest, "upgradingWritesExpectedFiles", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingANodeModuleTest, "shouldReWriteNodeDirsAndSkipIndex", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingANodeModuleTest, "resolvePathAliasesIsADevDependencyInNodeModules", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingANodeModuleTest, "movesResolvePathAliasesToDevDependencyOnUpgrade", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingANodeModuleTest, "removesBuildFromScriptsIfMatchesBrokenBuild", null);
__decorate([
(0, test_utils_1.test)()
], UpgradingANodeModuleTest, "doesNotRemoveBuildFromScriptsIfDoesNotMatchBrokenBuild", null);
//# sourceMappingURL=UpgradingANodeModule.test.js.map