feat(repo): add tests for create-nx-workspace (#3000)
This commit is contained in:
parent
b42f0a81bf
commit
ec1dfba6f6
72
e2e/create-nx-workspace.test.ts
Normal file
72
e2e/create-nx-workspace.test.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { forEachCli, runCreateWorkspace, uniq } from './utils';
|
||||
|
||||
forEachCli(() => {
|
||||
describe('create-nx-workspace', () => {
|
||||
it('should be able to create an empty workspace', () => {
|
||||
const wsName = uniq('empty');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'empty',
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to create an angular workspace', () => {
|
||||
const wsName = uniq('angular');
|
||||
const appName = uniq('app');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'angular',
|
||||
style: 'css',
|
||||
appName,
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to create an react workspace', () => {
|
||||
const wsName = uniq('react');
|
||||
const appName = uniq('app');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'react',
|
||||
style: 'css',
|
||||
appName,
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to create an next workspace', () => {
|
||||
const wsName = uniq('next');
|
||||
const appName = uniq('app');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'next',
|
||||
style: 'css',
|
||||
appName,
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to create an web-components workspace', () => {
|
||||
const wsName = uniq('web-components');
|
||||
const appName = uniq('app');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'web-components',
|
||||
style: 'css',
|
||||
appName,
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to create an angular + nest workspace', () => {
|
||||
const wsName = uniq('angular-nest');
|
||||
const appName = uniq('app');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'angular-nest',
|
||||
style: 'css',
|
||||
appName,
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to create an react + express workspace', () => {
|
||||
const wsName = uniq('react-express');
|
||||
const appName = uniq('app');
|
||||
runCreateWorkspace(wsName, {
|
||||
preset: 'react-express',
|
||||
style: 'css',
|
||||
appName,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
40
e2e/utils.ts
40
e2e/utils.ts
@ -70,31 +70,27 @@ export function workspaceConfigName() {
|
||||
return cli === 'angular' ? 'angular.json' : 'workspace.json';
|
||||
}
|
||||
|
||||
function patchPackageJsonDeps(addWorkspace = true) {
|
||||
const p = JSON.parse(readFileSync(tmpProjPath('package.json')).toString());
|
||||
const workspacePath = path.join(getCwd(), 'build', 'packages', 'workspace');
|
||||
const angularPath = path.join(getCwd(), 'build', 'packages', 'angular');
|
||||
const reactPath = path.join(getCwd(), 'build', 'packages', 'react');
|
||||
const storybookPath = path.join(getCwd(), 'build', 'packages', 'storybook');
|
||||
const jestPath = path.join(getCwd(), 'build', 'packages', 'jest');
|
||||
|
||||
if (addWorkspace) {
|
||||
p.devDependencies['@nrwl/workspace'] = `file:${workspacePath}`;
|
||||
export function runCreateWorkspace(
|
||||
name: string,
|
||||
{
|
||||
preset,
|
||||
appName,
|
||||
style,
|
||||
}: { preset: string; appName?: string; style?: string }
|
||||
) {
|
||||
let command = `npx create-nx-workspace@${process.env.PUBLISHED_VERSION} ${name} --cli=${cli} --preset=${preset} --no-interactive`;
|
||||
if (appName) {
|
||||
command += ` --appName ${appName}`;
|
||||
}
|
||||
p.devDependencies['@nrwl/angular'] = `file:${angularPath}`;
|
||||
p.devDependencies['@nrwl/react'] = `file:${reactPath}`;
|
||||
p.devDependencies['@nrwl/storybook'] = `file:${storybookPath}`;
|
||||
p.devDependencies['@nrwl/jest'] = `file:${jestPath}`;
|
||||
writeFileSync(tmpProjPath('package.json'), JSON.stringify(p, null, 2));
|
||||
}
|
||||
|
||||
export function runYarnInstall(silent: boolean = true) {
|
||||
const install = execSync(`yarn install`, {
|
||||
cwd: tmpProjPath(),
|
||||
...(silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {}),
|
||||
if (style) {
|
||||
command += ` --style ${style}`;
|
||||
}
|
||||
const create = execSync(command, {
|
||||
cwd: `./tmp/${cli}`,
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
env: process.env,
|
||||
});
|
||||
return install ? install.toString() : '';
|
||||
return create.toString();
|
||||
}
|
||||
|
||||
export function yarnAdd(pkg: string) {
|
||||
|
||||
@ -7,4 +7,4 @@ mkdir -p tmp/angular
|
||||
mkdir -p tmp/nx
|
||||
|
||||
export SELECTED_CLI=$1
|
||||
PUBLISHED_VERSION=9999.0.1 npm_config_registry=http://localhost:4872/ jest -c "./build/e2e/jest-config.js" --maxWorkers=1 "./build/e2e/(storybook|upgrade-module|web|angular-package|react-package|ngrx).test.js"
|
||||
PUBLISHED_VERSION=9999.0.1 npm_config_registry=http://localhost:4872/ jest -c "./build/e2e/jest-config.js" --maxWorkers=1 "./build/e2e/(storybook|upgrade-module|web|angular-package|react-package|ngrx|create-nx-workspace).test.js"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user