feat(repo): add a command to test create-nx-workspace
This commit is contained in:
parent
c7d075df49
commit
01575f8b3c
@ -61,6 +61,8 @@ yarn local-registry enable
|
||||
yarn local-registry disable
|
||||
```
|
||||
|
||||
You can also run `yarn test-create-nx-workspace 30.0.0`. It will set up local registry, publish the packages, create the workspace with Angular and React applications in it, and will run some basic checks against the workspace.
|
||||
|
||||
### Running Unit Tests
|
||||
|
||||
To make sure your changes do not break any unit tests, run the following:
|
||||
|
||||
1
e2e/commands/README
Normal file
1
e2e/commands/README
Normal file
@ -0,0 +1 @@
|
||||
These aren't exactly e2e tests. We are just using e2e utilities to implement these two commands.
|
||||
151
e2e/commands/create-nx-workspace.test.ts
Normal file
151
e2e/commands/create-nx-workspace.test.ts
Normal file
@ -0,0 +1,151 @@
|
||||
import { exec, execSync } from 'child_process';
|
||||
import { dirSync } from 'tmp';
|
||||
import { readdirSync, readFileSync, statSync, writeFileSync } from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
describe('create-nx-workspace', () => {
|
||||
afterEach(() => {
|
||||
execSync(`yarn local-registry disable`);
|
||||
});
|
||||
|
||||
it('creates a new project', async done => {
|
||||
if (!process.env.PUBLISHED_VERSION) {
|
||||
console.error(`Please provision the version you are publishing`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const tmpFolder = dirSync().name;
|
||||
const workspaceDir = `${tmpFolder}/happyorg`;
|
||||
|
||||
await startRegistry();
|
||||
await execCommand('Enabling local registry', `yarn local-registry enable`);
|
||||
await execCommand(
|
||||
'Publishing packages',
|
||||
`yarn nx-release ${process.env.PUBLISHED_VERSION} --local`
|
||||
);
|
||||
|
||||
await execCommand(
|
||||
`Create a workspace in "${workspaceDir}"`,
|
||||
`npx create-nx-workspace@latest happyorg --preset=angular --appName=ngapp --style=css`,
|
||||
tmpFolder
|
||||
);
|
||||
await execCommand(
|
||||
'Add ngrx to the Angular app',
|
||||
`ng g @nrwl/angular:ngrx state --module=apps/ngapp/src/app/app.module.ts --root`,
|
||||
workspaceDir
|
||||
);
|
||||
|
||||
await addReact(workspaceDir);
|
||||
await execCommand(
|
||||
`Generate a React app`,
|
||||
`ng g @nrwl/react:app reactapp`,
|
||||
workspaceDir
|
||||
);
|
||||
await execCommand(`Building angular app`, `ng build ngapp`, workspaceDir);
|
||||
await execCommand(`Building react app`, `ng build reactapp`, workspaceDir);
|
||||
|
||||
const webpacks = allVersionsOf(workspaceDir, 'webpack');
|
||||
if (webpacks.length > 1) {
|
||||
console.log(`more than one version of webpack: ${webpacks.join(', ')}`);
|
||||
}
|
||||
expect(webpacks.length).toEqual(1);
|
||||
|
||||
// filtering out rxjs in the listr package.
|
||||
const rxjs = allVersionsOf(workspaceDir, 'rxjs').filter(
|
||||
value => value !== '5.5.12'
|
||||
);
|
||||
if (rxjs.length > 1) {
|
||||
console.log(`more than one version of rxjs: ${rxjs.join(', ')}`);
|
||||
}
|
||||
expect(rxjs.length).toEqual(1);
|
||||
|
||||
console.log('The automatic tests have passed.');
|
||||
console.log(
|
||||
`Go to "${workspaceDir}" to verify that the workspace works as expected`
|
||||
);
|
||||
|
||||
done();
|
||||
}, 120000);
|
||||
});
|
||||
|
||||
function wait() {
|
||||
return new Promise(r => {
|
||||
setTimeout(() => r(), 500);
|
||||
});
|
||||
}
|
||||
|
||||
function startRegistry() {
|
||||
return new Promise((res, rej) => {
|
||||
const server = exec('yarn local-registry start');
|
||||
server.stdout.on('data', d => {
|
||||
if (d.toString().indexOf('http address') > -1) {
|
||||
res();
|
||||
}
|
||||
});
|
||||
|
||||
server.on('exit', s => {
|
||||
if (s !== 0) {
|
||||
rej(`Cannot start local registry`);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function allVersionsOf(dir: string, packageToCheck: string) {
|
||||
const r = packageJsonFilesInNodeModules(`${dir}/node_modules`)
|
||||
.map(p => {
|
||||
try {
|
||||
const parsed = JSON.parse(readFileSync(p).toString());
|
||||
if (parsed.name == packageToCheck) {
|
||||
return parsed.version;
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(p => !!p);
|
||||
return r.filter((value, index, self) => self.indexOf(value) === index);
|
||||
}
|
||||
|
||||
function addReact(workspaceDir: string) {
|
||||
const packageJson = JSON.parse(
|
||||
readFileSync(`${workspaceDir}/package.json`).toString()
|
||||
);
|
||||
packageJson.dependencies[`@nrwl/react`] = process.env.PUBLISHED_VERSION;
|
||||
writeFileSync(
|
||||
`${workspaceDir}/package.json`,
|
||||
JSON.stringify(packageJson, null, 2)
|
||||
);
|
||||
execSync(`npm config set registry http://localhost:4873/ && npm install`, {
|
||||
cwd: workspaceDir,
|
||||
shell: 'bash'
|
||||
});
|
||||
}
|
||||
|
||||
async function execCommand(description: string, cmd: string, cwd?: string) {
|
||||
console.log(description);
|
||||
execSync(cmd, {
|
||||
stdio: [0, 1, 2],
|
||||
cwd
|
||||
});
|
||||
await wait();
|
||||
}
|
||||
|
||||
function packageJsonFilesInNodeModules(dirName: string): string[] {
|
||||
let res = [];
|
||||
try {
|
||||
readdirSync(dirName).forEach(c => {
|
||||
try {
|
||||
const child = path.join(dirName, c);
|
||||
const s = statSync(child);
|
||||
if (child.endsWith('package.json')) {
|
||||
res.push(child);
|
||||
} else if (s.isDirectory()) {
|
||||
res = [...res, ...packageJsonFilesInNodeModules(child)];
|
||||
}
|
||||
} catch (e) {}
|
||||
});
|
||||
} catch (e) {}
|
||||
return res;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import { ensureProject, forEachCli, newProject, runCLI } from './utils';
|
||||
import { ensureProject, forEachCli, newProject, runCLI } from '../utils';
|
||||
|
||||
forEachCli(() => {
|
||||
describe('create playground', () => {
|
||||
@ -11,17 +11,18 @@
|
||||
"checkcommit": "node ./scripts/commit-lint.js",
|
||||
"e2e": "./scripts/e2e.sh",
|
||||
"e2e-rerun": "./scripts/e2e-rerun.sh",
|
||||
"create-playground": "./scripts/e2e.sh create-playground",
|
||||
"create-playground": "./scripts/create-playground.sh",
|
||||
"update-playground": "./scripts/update-playground.sh",
|
||||
"e2e-ci1": "./scripts/e2e-ci1.sh",
|
||||
"e2e-ci2": "./scripts/e2e-ci2.sh",
|
||||
"test-create-nx-workspace": "./scripts/test-create-nx-workspace.sh",
|
||||
"format": "./scripts/format.sh",
|
||||
"linknpm": "./scripts/link.sh",
|
||||
"nx-release": "./scripts/nx-release.js",
|
||||
"copy": "./scripts/copy.sh",
|
||||
"test": "yarn linknpm fast && ./scripts/test.sh",
|
||||
"test:all": "yarn linknpm fast && ./scripts/test_angular_runtime.sh && ./scripts/test.sh",
|
||||
"checkformat": "./scripts/check_format.sh",
|
||||
"test:all": "yarn linknpm fast && scripts/test-angular-runtime.sh && ./scripts/test.sh",
|
||||
"checkformat": "scripts/check-format.sh",
|
||||
"checkimports": "node ./scripts/check-imports.js",
|
||||
"checkversions": "ts-node ./scripts/check-versions.ts",
|
||||
"local-registry": "./scripts/local-registry.sh",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nrwl/cli",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "create-nx-plugin",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.1",
|
||||
"description": "Extensible Dev Tools for Monorepos",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "create-nx-workspace",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.1",
|
||||
"description": "Extensible Dev Tools for Monorepos",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
11
scripts/create-playground.sh
Executable file
11
scripts/create-playground.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
./scripts/link.sh
|
||||
|
||||
rm -rf tmp
|
||||
mkdir -p tmp/angular
|
||||
mkdir -p tmp/nx
|
||||
|
||||
jest --maxWorkers=1 ./build/e2e/commands/create-playground.test.js
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ "$1" = "fast" ]; then
|
||||
./scripts/build_for_test.sh
|
||||
./scripts/build-for-test.sh
|
||||
fi
|
||||
|
||||
if [ "$1" != "fast" ]; then
|
||||
|
||||
@ -132,22 +132,7 @@ childProcess.execSync(`find build/npm -maxdepth 1 -name "*.tgz" -delete`, {
|
||||
*/
|
||||
const DRY_RUN = !!parsedArgs['dry-run'];
|
||||
|
||||
/**
|
||||
* Set the static options for release-it
|
||||
*/
|
||||
const options = {
|
||||
'dry-run': DRY_RUN,
|
||||
changelogCommand: 'conventional-changelog -p angular | tail -n +3',
|
||||
/**
|
||||
* Needed so that we can leverage conventional-changelog to generate
|
||||
* the changelog
|
||||
*/
|
||||
safeBump: false,
|
||||
/**
|
||||
* All the package.json files that will have their version updated
|
||||
* by release-it
|
||||
*/
|
||||
pkgFiles: [
|
||||
const pkgFiles = [
|
||||
'package.json',
|
||||
'build/npm/create-nx-workspace/package.json',
|
||||
'build/npm/create-nx-plugin/package.json',
|
||||
@ -167,7 +152,23 @@ const options = {
|
||||
'build/npm/eslint-plugin-nx/package.json',
|
||||
'build/npm/linter/package.json',
|
||||
'build/npm/nx-plugin/package.json'
|
||||
],
|
||||
];
|
||||
/**
|
||||
* Set the static options for release-it
|
||||
*/
|
||||
const options = {
|
||||
'dry-run': DRY_RUN,
|
||||
changelogCommand: 'conventional-changelog -p angular | tail -n +3',
|
||||
/**
|
||||
* Needed so that we can leverage conventional-changelog to generate
|
||||
* the changelog
|
||||
*/
|
||||
safeBump: false,
|
||||
/**
|
||||
* All the package.json files that will have their version updated
|
||||
* by release-it
|
||||
*/
|
||||
pkgFiles: pkgFiles,
|
||||
increment: parsedVersion.version,
|
||||
requireUpstream: false,
|
||||
github: {
|
||||
@ -191,26 +192,34 @@ const options = {
|
||||
requireCleanWorkingDir: false
|
||||
};
|
||||
|
||||
releaseIt(options)
|
||||
childProcess.execSync('rm -rf ./build/packages/bazel');
|
||||
childProcess.execSync('rm -rf ./build/npm/bazel');
|
||||
|
||||
if (parsedArgs.local) {
|
||||
pkgFiles.forEach(p => {
|
||||
const content = JSON.parse(fs.readFileSync(p).toString());
|
||||
content.version = parsedVersion.version;
|
||||
fs.writeFileSync(p, JSON.stringify(content, null, 2));
|
||||
});
|
||||
childProcess.execSync(
|
||||
`./scripts/publish.sh ${parsedVersion.version} latest --local`,
|
||||
{
|
||||
stdio: [0, 1, 2]
|
||||
}
|
||||
);
|
||||
process.exit(0);
|
||||
} else {
|
||||
releaseIt(options)
|
||||
.then(output => {
|
||||
if (DRY_RUN) {
|
||||
console.warn('WARNING: In DRY_RUN mode - not running publishing script');
|
||||
console.warn(
|
||||
'WARNING: In DRY_RUN mode - not running publishing script'
|
||||
);
|
||||
process.exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
// if (parsedArgs.nobazel) {
|
||||
childProcess.execSync('rm -rf ./build/packages/bazel');
|
||||
childProcess.execSync('rm -rf ./build/npm/bazel');
|
||||
// }
|
||||
|
||||
/**
|
||||
* We always use either "latest" or "next" (i.e. no separate tags for alpha, beta etc)
|
||||
*/
|
||||
const npmTag = parsedVersion.isPrerelease ? 'next' : 'latest';
|
||||
const npmPublishCommand = `./scripts/publish.sh ${
|
||||
output.version
|
||||
} ${npmTag} ${parsedArgs.local ? '--local' : ''}`;
|
||||
const npmPublishCommand = `./scripts/publish.sh ${output.version} ${npmTag}`;
|
||||
console.log('Executing publishing script for all packages:');
|
||||
console.log(`> ${npmPublishCommand}`);
|
||||
console.log(
|
||||
@ -225,3 +234,4 @@ releaseIt(options)
|
||||
console.error(err.message);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
4
scripts/test-create-nx-workspace.sh
Executable file
4
scripts/test-create-nx-workspace.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
./scripts/link.sh
|
||||
PUBLISHED_VERSION=$1 jest --maxWorkers=1 ./build/e2e/commands/create-nx-workspace.test.js
|
||||
Loading…
x
Reference in New Issue
Block a user