nx/packages/vue/src/generators/application/application.spec.ts
Colum Ferry dfd7241ed5
fix(testing): adding e2e projects should register e2e-ci targetDefaults (#27185)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->



## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-08-07 12:25:32 -04:00

119 lines
3.7 KiB
TypeScript

import 'nx/src/internal-testing-utils/mock-project-graph';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import {
Tree,
readProjectConfiguration,
readNxJson,
updateNxJson,
} from '@nx/devkit';
import { applicationGenerator } from './application';
import { Schema } from './schema';
describe('application generator', () => {
let tree: Tree;
const options: Schema = { name: 'test' } as Schema;
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});
it('should run successfully', async () => {
await applicationGenerator(tree, options);
const config = readProjectConfiguration(tree, 'test');
expect(config).toBeDefined();
});
it('should set up project correctly with given options', async () => {
const nxJson = readNxJson(tree);
nxJson.plugins ??= [];
nxJson.plugins.push({
plugin: '@nx/vite/plugin',
options: {
buildTargetName: 'build',
previewTargetName: 'preview',
},
});
updateNxJson(tree, nxJson);
await applicationGenerator(tree, {
...options,
unitTestRunner: 'vitest',
e2eTestRunner: 'playwright',
addPlugin: true,
});
expect(tree.read('.eslintrc.json', 'utf-8')).toMatchSnapshot();
expect(tree.read('test/vite.config.ts', 'utf-8')).toMatchSnapshot();
expect(tree.read('test/.eslintrc.json', 'utf-8')).toMatchSnapshot();
expect(tree.read('test/src/app/App.spec.ts', 'utf-8')).toMatchSnapshot();
expect(
tree.read('test-e2e/playwright.config.ts', 'utf-8')
).toMatchSnapshot();
expect(listFiles(tree)).toMatchSnapshot();
expect(readNxJson(tree).targetDefaults['e2e-ci--**/*'])
.toMatchInlineSnapshot(`
{
"dependsOn": [
"^build",
],
}
`);
});
it('should set up project correctly for cypress', async () => {
const nxJson = readNxJson(tree);
nxJson.plugins ??= [];
nxJson.plugins.push({
plugin: '@nx/vite/plugin',
options: {
buildTargetName: 'build',
previewTargetName: 'preview',
},
});
updateNxJson(tree, nxJson);
await applicationGenerator(tree, {
...options,
addPlugin: true,
unitTestRunner: 'vitest',
e2eTestRunner: 'cypress',
});
expect(tree.read('.eslintrc.json', 'utf-8')).toMatchSnapshot();
expect(tree.read('test/vite.config.ts', 'utf-8')).toMatchSnapshot();
expect(tree.read('test/.eslintrc.json', 'utf-8')).toMatchSnapshot();
expect(tree.read('test/src/app/App.spec.ts', 'utf-8')).toMatchSnapshot();
expect(tree.read('test-e2e/cypress.config.ts', 'utf-8')).toMatchSnapshot();
});
it('should set up project correctly with PascalCase name', async () => {
await applicationGenerator(tree, {
...options,
name: 'TestApp',
unitTestRunner: 'vitest',
projectNameAndRootFormat: 'as-provided',
});
expect(tree.read('.eslintrc.json', 'utf-8')).toMatchSnapshot();
expect(tree.read('TestApp/vite.config.ts', 'utf-8')).toMatchSnapshot();
expect(tree.read('TestApp/.eslintrc.json', 'utf-8')).toMatchSnapshot();
expect(tree.read('TestApp/src/app/App.spec.ts', 'utf-8')).toMatchSnapshot();
expect(listFiles(tree)).toMatchSnapshot();
});
it('should not use stylesheet if --style=none', async () => {
await applicationGenerator(tree, { ...options, style: 'none' });
expect(tree.exists('test/src/style.none')).toBeFalsy();
expect(tree.read('test/src/main.ts', 'utf-8')).not.toContain('styles.none');
});
});
function listFiles(tree: Tree): string[] {
const files = new Set<string>();
tree.listChanges().forEach((change) => {
if (change.type !== 'DELETE') {
files.add(change.path);
}
});
return Array.from(files).sort((a, b) => a.localeCompare(b));
}