fix(node): e2e target fails out of the box (#22987)
This commit is contained in:
parent
df7e40d547
commit
9cf8c29d27
@ -217,6 +217,23 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
|
||||||
|
it("should exclude 'test' target from e2e project that uses jest", async () => {
|
||||||
|
const appName = uniq('nodeapp');
|
||||||
|
|
||||||
|
runCLI(
|
||||||
|
`generate @nx/node:app ${appName} --project-name-and-root-format=as-provided --no-interactive`
|
||||||
|
);
|
||||||
|
|
||||||
|
const nxJson = JSON.parse(readFile('nx.json'));
|
||||||
|
expect(nxJson.plugins).toBeDefined();
|
||||||
|
|
||||||
|
const jestPlugin = nxJson.plugins.find(
|
||||||
|
(p) => p.plugin === '@nx/jest/plugin'
|
||||||
|
);
|
||||||
|
expect(jestPlugin).toBeDefined();
|
||||||
|
expect(jestPlugin.exclude).toContain(`${appName}-e2e/**/*`);
|
||||||
|
});
|
||||||
|
|
||||||
it('should be able to generate an express application', async () => {
|
it('should be able to generate an express application', async () => {
|
||||||
const nodeapp = uniq('nodeapp');
|
const nodeapp = uniq('nodeapp');
|
||||||
const originalEnvPort = process.env.PORT;
|
const originalEnvPort = process.env.PORT;
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
runTasksInSerial,
|
runTasksInSerial,
|
||||||
Tree,
|
Tree,
|
||||||
|
updateJson,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
||||||
import { Linter, lintProjectGenerator } from '@nx/eslint';
|
import { Linter, lintProjectGenerator } from '@nx/eslint';
|
||||||
@ -57,9 +58,37 @@ export async function e2eProjectGeneratorInternal(
|
|||||||
jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
|
jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
|
||||||
passWithNoTests: true,
|
passWithNoTests: true,
|
||||||
},
|
},
|
||||||
|
dependsOn: [`${options.project}:build`],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
// TODO(@nicholas): Find a better way to get build target
|
||||||
|
|
||||||
|
// We remove the 'test' target from the e2e project because it is not needed
|
||||||
|
// The 'e2e' target is the one that should run the tests for the e2e project
|
||||||
|
const nxJson = readNxJson(host);
|
||||||
|
const hasPlugin = nxJson.plugins?.some((p) => {
|
||||||
|
if (typeof p !== 'string' && p.plugin === '@nx/jest/plugin') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (hasPlugin) {
|
||||||
|
updateJson(host, 'nx.json', (json) => {
|
||||||
|
return {
|
||||||
|
...json,
|
||||||
|
plugins: json.plugins?.map((p) => {
|
||||||
|
if (typeof p !== 'string' && p.plugin === '@nx/jest/plugin') {
|
||||||
|
return {
|
||||||
|
...p,
|
||||||
|
exclude: [...(p.exclude || []), `${options.e2eProjectRoot}/**/*`],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (options.projectType === 'server') {
|
if (options.projectType === 'server') {
|
||||||
generateFiles(
|
generateFiles(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user