feat(repo): add tests for create-nx-workspace (#3000)

This commit is contained in:
Jason Jean 2020-05-15 11:30:11 -04:00 committed by GitHub
parent b42f0a81bf
commit ec1dfba6f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 23 deletions

View 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,
});
});
});
});

View File

@ -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) {

View File

@ -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"