fix(testing): web and react application fixes for vitest's insourceTests (#13447)
This commit is contained in:
parent
5af4ae0f48
commit
f0f60fbb94
@ -1002,5 +1002,23 @@ describe('app', () => {
|
|||||||
expect(viteAppTree.exists('/apps/my-app/index.html')).toBe(true);
|
expect(viteAppTree.exists('/apps/my-app/index.html')).toBe(true);
|
||||||
expect(viteAppTree.exists('/apps/my-app/vite.config.ts')).toBe(true);
|
expect(viteAppTree.exists('/apps/my-app/vite.config.ts')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not include a spec file when the bundler or unitTestRunner is vite and insourceTests is false', async () => {
|
||||||
|
// check to make sure that the other spec file exists
|
||||||
|
expect(viteAppTree.exists('/apps/my-app/src/app/app.spec.tsx')).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
await applicationGenerator(viteAppTree, {
|
||||||
|
...schema,
|
||||||
|
name: 'insourceTests',
|
||||||
|
bundler: 'vite',
|
||||||
|
inSourceTests: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
viteAppTree.exists('/apps/insourceTests/src/app/app.spec.tsx')
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -111,6 +111,18 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
|
|||||||
tasks.push(vitestTask);
|
tasks.push(vitestTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(options.bundler === 'vite' || options.unitTestRunner === 'vitest') &&
|
||||||
|
options.inSourceTests
|
||||||
|
) {
|
||||||
|
host.delete(
|
||||||
|
joinPathFragments(
|
||||||
|
options.appProjectRoot,
|
||||||
|
`src/app/${options.fileName}.spec.tsx`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const lintTask = await addLinting(host, options);
|
const lintTask = await addLinting(host, options);
|
||||||
tasks.push(lintTask);
|
tasks.push(lintTask);
|
||||||
|
|
||||||
@ -120,8 +132,10 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
|
|||||||
if (options.unitTestRunner === 'jest') {
|
if (options.unitTestRunner === 'jest') {
|
||||||
const jestTask = await addJest(host, options);
|
const jestTask = await addJest(host, options);
|
||||||
tasks.push(jestTask);
|
tasks.push(jestTask);
|
||||||
updateSpecConfig(host, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle tsconfig.spec.json for jest or vitest
|
||||||
|
updateSpecConfig(host, options);
|
||||||
const styledTask = addStyledModuleDependencies(host, options.styledModule);
|
const styledTask = addStyledModuleDependencies(host, options.styledModule);
|
||||||
tasks.push(styledTask);
|
tasks.push(styledTask);
|
||||||
const routingTask = addRouting(host, options);
|
const routingTask = addRouting(host, options);
|
||||||
|
|||||||
@ -573,5 +573,21 @@ describe('app', () => {
|
|||||||
expect(viteAppTree.exists('/apps/my-app/index.html')).toBe(true);
|
expect(viteAppTree.exists('/apps/my-app/index.html')).toBe(true);
|
||||||
expect(viteAppTree.exists('/apps/my-app/vite.config.ts')).toBe(true);
|
expect(viteAppTree.exists('/apps/my-app/vite.config.ts')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not include a spec file when the bundler or unitTestRunner is vite and insourceTests is false', async () => {
|
||||||
|
expect(
|
||||||
|
viteAppTree.exists('/apps/my-app/src/app/app.element.spec.ts')
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
await applicationGenerator(viteAppTree, {
|
||||||
|
name: 'insourceTests',
|
||||||
|
bundler: 'vite',
|
||||||
|
inSourceTests: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
viteAppTree.exists('/apps/insource-tests/src/app/app.element.spec.ts')
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -206,10 +206,11 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
|
|||||||
host.delete(joinPathFragments(options.appProjectRoot, 'src/environments'));
|
host.delete(joinPathFragments(options.appProjectRoot, 'src/environments'));
|
||||||
|
|
||||||
const viteTask = await viteConfigurationGenerator(host, {
|
const viteTask = await viteConfigurationGenerator(host, {
|
||||||
uiFramework: 'react',
|
uiFramework: 'none',
|
||||||
project: options.projectName,
|
project: options.projectName,
|
||||||
newProject: true,
|
newProject: true,
|
||||||
includeVitest: true,
|
includeVitest: true,
|
||||||
|
inSourceTests: options.inSourceTests,
|
||||||
});
|
});
|
||||||
tasks.push(viteTask);
|
tasks.push(viteTask);
|
||||||
}
|
}
|
||||||
@ -223,6 +224,15 @@ export async function applicationGenerator(host: Tree, schema: Schema) {
|
|||||||
tasks.push(vitestTask);
|
tasks.push(vitestTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(options.bundler === 'vite' || options.unitTestRunner === 'vitest') &&
|
||||||
|
options.inSourceTests
|
||||||
|
) {
|
||||||
|
host.delete(
|
||||||
|
joinPathFragments(options.appProjectRoot, `src/app/app.element.spec.ts`)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const lintTask = await lintProjectGenerator(host, {
|
const lintTask = await lintProjectGenerator(host, {
|
||||||
linter: options.linter,
|
linter: options.linter,
|
||||||
project: options.projectName,
|
project: options.projectName,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user