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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
38
e2e/utils.ts
38
e2e/utils.ts
@ -70,31 +70,27 @@ export function workspaceConfigName() {
|
|||||||
return cli === 'angular' ? 'angular.json' : 'workspace.json';
|
return cli === 'angular' ? 'angular.json' : 'workspace.json';
|
||||||
}
|
}
|
||||||
|
|
||||||
function patchPackageJsonDeps(addWorkspace = true) {
|
export function runCreateWorkspace(
|
||||||
const p = JSON.parse(readFileSync(tmpProjPath('package.json')).toString());
|
name: string,
|
||||||
const workspacePath = path.join(getCwd(), 'build', 'packages', 'workspace');
|
{
|
||||||
const angularPath = path.join(getCwd(), 'build', 'packages', 'angular');
|
preset,
|
||||||
const reactPath = path.join(getCwd(), 'build', 'packages', 'react');
|
appName,
|
||||||
const storybookPath = path.join(getCwd(), 'build', 'packages', 'storybook');
|
style,
|
||||||
const jestPath = path.join(getCwd(), 'build', 'packages', 'jest');
|
}: { preset: string; appName?: string; style?: string }
|
||||||
|
) {
|
||||||
if (addWorkspace) {
|
let command = `npx create-nx-workspace@${process.env.PUBLISHED_VERSION} ${name} --cli=${cli} --preset=${preset} --no-interactive`;
|
||||||
p.devDependencies['@nrwl/workspace'] = `file:${workspacePath}`;
|
if (appName) {
|
||||||
|
command += ` --appName ${appName}`;
|
||||||
}
|
}
|
||||||
p.devDependencies['@nrwl/angular'] = `file:${angularPath}`;
|
if (style) {
|
||||||
p.devDependencies['@nrwl/react'] = `file:${reactPath}`;
|
command += ` --style ${style}`;
|
||||||
p.devDependencies['@nrwl/storybook'] = `file:${storybookPath}`;
|
|
||||||
p.devDependencies['@nrwl/jest'] = `file:${jestPath}`;
|
|
||||||
writeFileSync(tmpProjPath('package.json'), JSON.stringify(p, null, 2));
|
|
||||||
}
|
}
|
||||||
|
const create = execSync(command, {
|
||||||
export function runYarnInstall(silent: boolean = true) {
|
cwd: `./tmp/${cli}`,
|
||||||
const install = execSync(`yarn install`, {
|
stdio: ['pipe', 'pipe', 'pipe'],
|
||||||
cwd: tmpProjPath(),
|
|
||||||
...(silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {}),
|
|
||||||
env: process.env,
|
env: process.env,
|
||||||
});
|
});
|
||||||
return install ? install.toString() : '';
|
return create.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function yarnAdd(pkg: string) {
|
export function yarnAdd(pkg: string) {
|
||||||
|
|||||||
@ -7,4 +7,4 @@ mkdir -p tmp/angular
|
|||||||
mkdir -p tmp/nx
|
mkdir -p tmp/nx
|
||||||
|
|
||||||
export SELECTED_CLI=$1
|
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