@nx/angular
Version:
31 lines (30 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.componentTestGenerator = componentTestGenerator;
const devkit_1 = require("@nx/devkit");
const versions_1 = require("../../utils/versions");
const storybook_inputs_1 = require("../utils/storybook-ast/storybook-inputs");
async function componentTestGenerator(tree, options) {
(0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
const { assertMinimumCypressVersion } = require('@nx/cypress/src/utils/versions');
assertMinimumCypressVersion(10);
const { root } = (0, devkit_1.readProjectConfiguration)(tree, options.project);
const componentDirPath = (0, devkit_1.joinPathFragments)(root, options.componentDir);
const componentFilePath = (0, devkit_1.joinPathFragments)(componentDirPath, `${options.componentFileName}.ts`);
const componentTestFilePath = (0, devkit_1.joinPathFragments)(componentDirPath, `${options.componentFileName}.cy.ts`);
if (tree.exists(componentFilePath) && !tree.exists(componentTestFilePath)) {
const props = (0, storybook_inputs_1.getComponentProps)(tree, componentFilePath, storybook_inputs_1.getArgsDefaultValue, false);
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), componentDirPath, {
componentName: options.componentName,
componentFileName: options.componentFileName.startsWith('./')
? options.componentFileName.slice(2)
: options.componentFileName,
props: props.filter((p) => typeof p.defaultValue !== 'undefined'),
tpl: '',
});
}
if (!options.skipFormat) {
await (0, devkit_1.formatFiles)(tree);
}
}
exports.default = componentTestGenerator;