Skip to content

Commit

Permalink
test(schematics): add tests for create-nx-workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Feb 4, 2018
1 parent 6756e19 commit 125852d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: node_js
dist: trusty
sudo: required
node_js:
- '6.9.5'
- '8.9.3'
before_install:
- export DISPLAY=:99.0
install:
Expand Down
46 changes: 46 additions & 0 deletions e2e/schematics/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { checkFilesExist, createNxWorkspace, readFile } from '../utils';

/**
* Too slow to run on CI :(
*/
xdescribe('CreateNxWorkspace', () => {
it(
'should create a new workspace using npm',
() => {
const res = createNxWorkspace('proj --npmScope=myscope');
expect(res).toContain("Project 'proj' successfully created.");

const config = JSON.parse(readFile('.angular-cli.json'));
expect(config.project.name).toEqual('proj');
expect(config.project.npmScope).toEqual('myscope');

checkFilesExist('package-lock.json');
},
1000000
);

it(
'should create a new workspace using yarn',
() => {
const res = createNxWorkspace('proj --npmScope=myscope --yarn');
expect(res).toContain("Project 'proj' successfully created.");

const config = JSON.parse(readFile('.angular-cli.json'));
expect(config.project.name).toEqual('proj');
expect(config.project.npmScope).toEqual('myscope');

checkFilesExist('yarn.lock');
},
1000000
);

it(
'should error when no name is given',
() => {
expect(() => createNxWorkspace('')).toThrowError(
'Please provide a project name'
);
},
1000000
);
});
10 changes: 10 additions & 0 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export function newProject(): void {
execSync('cp -a ./tmp/proj_backup ./tmp/proj');
}

export function createNxWorkspace(command: string): string {
cleanup();
return execSync(
`node ../node_modules/@nrwl/schematics/bin/create-nx-workspace.js ${command}`,
{
cwd: `./tmp`
}
).toString();
}

export function copyMissingPackages(): void {
const modulesToCopy = ['@ngrx', 'jasmine-marbles', '@nrwl', 'angular', '@angular/upgrade', '@angular/cli'];
modulesToCopy.forEach(m => copyNodeModule(projectName, m));
Expand Down

0 comments on commit 125852d

Please sign in to comment.