Skip to content

Commit

Permalink
reformat the code using the new prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Mar 16, 2018
1 parent dba3ce4 commit 74d920a
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 99 deletions.
8 changes: 6 additions & 2 deletions e2e/schematics/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ describe('Nrwl Workspace', () => {
() => {
newProject();
newApp('myApp --directory=myDir --routing');
newLib('myLib --directory=myDir --routing --lazy --parentModule=apps/my-dir/my-app/src/app/app.module.ts');
newLib(
'myLib --directory=myDir --routing --lazy --parentModule=apps/my-dir/my-app/src/app/app.module.ts'
);

runCLI('build --aot -a=my-dir/my-app');
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
Expand All @@ -50,7 +52,9 @@ describe('Nrwl Workspace', () => {
() => {
newProject();
newApp('myApp --directory=myDir --routing');
newLib('myLib --directory=myDir --routing --parentModule=apps/my-dir/my-app/src/app/app.module.ts');
newLib(
'myLib --directory=myDir --routing --parentModule=apps/my-dir/my-app/src/app/app.module.ts'
);

runCLI('build --aot -a=my-dir/my-app');
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
Expand Down
9 changes: 8 additions & 1 deletion e2e/schematics/bazel-application.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import {checkFilesExist, newApp, newBazelProject, newLib, runCLI, updateFile} from '../utils';
import {
checkFilesExist,
newApp,
newBazelProject,
newLib,
runCLI,
updateFile
} from '../utils';

xdescribe('Nrwl Workspace (Bazel)', () => {
it(
Expand Down
65 changes: 49 additions & 16 deletions e2e/schematics/command-line.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { newApp, newLib, newProject, readFile, runCLI, runCommand, updateFile } from '../utils';
import {
newApp,
newLib,
newProject,
readFile,
runCLI,
runCommand,
updateFile
} from '../utils';

describe('Command line', () => {
it(
Expand All @@ -13,9 +21,9 @@ describe('Command line', () => {
newLib('validtaglib --tags=validtag');

const tslint = JSON.parse(readFile('tslint.json'));
tslint.rules["nx-enforce-module-boundaries"][1].depConstraints = [
{ "sourceTag": "validtag", "onlyDependOnLibsWithTags": ["validtag"] },
...tslint.rules["nx-enforce-module-boundaries"][1].depConstraints
tslint.rules['nx-enforce-module-boundaries'][1].depConstraints = [
{ sourceTag: 'validtag', onlyDependOnLibsWithTags: ['validtag'] },
...tslint.rules['nx-enforce-module-boundaries'][1].depConstraints
];
updateFile('tslint.json', JSON.stringify(tslint, null, 2));

Expand All @@ -38,7 +46,9 @@ describe('Command line', () => {
expect(out).toContain('imports of lazy-loaded libraries are forbidden');
expect(out).toContain('deep imports into libraries are forbidden');
expect(out).toContain('imports of apps are forbidden');
expect(out).toContain('A project tagged with "validtag" can only depend on libs tagged with "validtag"');
expect(out).toContain(
'A project tagged with "validtag" can only depend on libs tagged with "validtag"'
);
},
1000000
);
Expand All @@ -59,7 +69,9 @@ describe('Command line', () => {
`
);
const checkOut = runCommand('npm run update:check');
expect(checkOut).toContain('Run "npm run update" to run the following migrations');
expect(checkOut).toContain(
'Run "npm run update" to run the following migrations'
);
expect(checkOut).toContain('20200101-test-migration');

const migrateOut = runCommand('npm run update');
Expand All @@ -82,7 +94,9 @@ describe('Command line', () => {
);

const checkOut2 = runCommand('npm run update:check');
expect(checkOut2).toContain('Run "npm run update" to run the following migrations');
expect(checkOut2).toContain(
'Run "npm run update" to run the following migrations'
);
expect(checkOut2).toContain('20200102-test-migration');

const skipOut = runCommand('npm run update:skip');
Expand All @@ -104,16 +118,25 @@ describe('Command line', () => {
newApp('myapp2');
newLib('mylib');

updateFile('apps/myapp/src/app/app.component.spec.ts', `import '@proj/mylib';`);
updateFile(
'apps/myapp/src/app/app.component.spec.ts',
`import '@proj/mylib';`
);

const affectedApps = runCommand('npm run affected:apps -- --files="libs/mylib/index.ts"');
const affectedApps = runCommand(
'npm run affected:apps -- --files="libs/mylib/index.ts"'
);
expect(affectedApps).toContain('myapp');
expect(affectedApps).not.toContain('myapp2');

const build = runCommand('npm run affected:build -- --files="libs/mylib/index.ts"');
const build = runCommand(
'npm run affected:build -- --files="libs/mylib/index.ts"'
);
expect(build).toContain('Building myapp');

const e2e = runCommand('npm run affected:e2e -- --files="libs/mylib/index.ts"');
const e2e = runCommand(
'npm run affected:e2e -- --files="libs/mylib/index.ts"'
);
expect(e2e).toContain('should display welcome message');
},
1000000
Expand Down Expand Up @@ -161,7 +184,9 @@ describe('Command line', () => {

try {
// this will group it by lib, so all three files will be "marked"
runCommand('npm run -s format:check -- --files="libs/mylib/index.ts" --libs-and-apps');
runCommand(
'npm run -s format:check -- --files="libs/mylib/index.ts" --libs-and-apps'
);
fail('boom');
} catch (e) {
expect(e.stdout.toString()).toContain('libs/mylib/index.ts');
Expand All @@ -174,8 +199,12 @@ describe('Command line', () => {
fail('boom');
} catch (e) {
expect(e.stdout.toString()).toContain('apps/myapp/src/main.ts');
expect(e.stdout.toString()).toContain('apps/myapp/src/app/app.module.ts');
expect(e.stdout.toString()).toContain('apps/myapp/src/app/app.component.ts');
expect(e.stdout.toString()).toContain(
'apps/myapp/src/app/app.module.ts'
);
expect(e.stdout.toString()).toContain(
'apps/myapp/src/app/app.component.ts'
);
}
runCommand(
'npm run format:write -- --files="apps/myapp/src/app/app.module.ts,apps/myapp/src/app/app.component.ts"'
Expand All @@ -186,8 +215,12 @@ describe('Command line', () => {
fail('boom');
} catch (e) {
expect(e.stdout.toString()).toContain('apps/myapp/src/main.ts');
expect(e.stdout.toString()).not.toContain('apps/myapp/src/app/app.module.ts');
expect(e.stdout.toString()).not.toContain('apps/myapp/src/app/app.component.ts');
expect(e.stdout.toString()).not.toContain(
'apps/myapp/src/app/app.module.ts'
);
expect(e.stdout.toString()).not.toContain(
'apps/myapp/src/app/app.component.ts'
);
}

runCommand('npm run format:write');
Expand Down
4 changes: 3 additions & 1 deletion e2e/schematics/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ xdescribe('CreateNxWorkspace', () => {
it(
'should create a new workspace with the --directory option',
() => {
const res = createNxWorkspace('myproj --npmScope=myscope --directory=proj');
const res = createNxWorkspace(
'myproj --npmScope=myscope --directory=proj'
);
expect(res).toContain("Project 'myproj' successfully created.");
checkFilesExist('package-lock.json');
},
Expand Down
5 changes: 4 additions & 1 deletion e2e/schematics/downgrade-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ describe('DowngradeModule', () => {
newProject();
newApp('myapp');

updateFile('apps/myapp/src/legacy.js', `window.angular.module('legacy', []);`);
updateFile(
'apps/myapp/src/legacy.js',
`window.angular.module('legacy', []);`
);

runCLI('generate downgrade-module legacy --angularJsImport=./legacy');

Expand Down
4 changes: 3 additions & 1 deletion e2e/schematics/ngrx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ describe('ngrx', () => {
() => {
newProject();
newApp('myapp');
runCLI('generate ngrx app --module=apps/myapp/src/app/app.module.ts --root --collection=@nrwl/schematics');
runCLI(
'generate ngrx app --module=apps/myapp/src/app/app.module.ts --root --collection=@nrwl/schematics'
);
updateFile(
'apps/myapp/src/app/+state/app.interfaces.ts',
`
Expand Down
5 changes: 4 additions & 1 deletion e2e/schematics/upgrade-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ describe('Upgrade', () => {

updateFile('apps/myapp/src/app/app.component.spec.ts', ``);

runCLI('generate upgrade-module legacy --angularJsImport=./legacy ' + '--angularJsCmpSelector=rootLegacyCmp');
runCLI(
'generate upgrade-module legacy --angularJsImport=./legacy ' +
'--angularJsCmpSelector=rootLegacyCmp'
);

runCLI('build');
runCLI('test --single-run');
Expand Down
50 changes: 39 additions & 11 deletions e2e/schematics/workspace.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import {checkFilesExist, cleanup, copyMissingPackages, readFile, runCLI, runNgNew, updateFile} from '../utils';
import {angularCliSchema} from '../../packages/schematics/src/lib-versions';
import {
checkFilesExist,
cleanup,
copyMissingPackages,
readFile,
runCLI,
runNgNew,
updateFile
} from '../utils';
import { angularCliSchema } from '../../packages/schematics/src/lib-versions';

describe('Nrwl Convert to Nx Workspace', () => {
beforeEach(cleanup);
Expand Down Expand Up @@ -31,20 +39,30 @@ describe('Nrwl Convert to Nx Workspace', () => {
updateFile('.angular-cli.json', JSON.stringify(angularCLIJson, null, 2));

// run the command
runCLI('generate workspace proj --npmScope=proj --collection=@nrwl/schematics');
runCLI(
'generate workspace proj --npmScope=proj --collection=@nrwl/schematics'
);

// check that prettier config exits and that files have been moved!
checkFilesExist('.prettierrc', 'apps/proj/src/main.ts', 'apps/proj/src/app/app.module.ts');
checkFilesExist(
'.prettierrc',
'apps/proj/src/main.ts',
'apps/proj/src/app/app.module.ts'
);

// check that package.json got merged
const updatedPackageJson = JSON.parse(readFile('package.json'));
expect(updatedPackageJson.description).toEqual('some description');
expect(updatedPackageJson.devDependencies['@nrwl/schematics']).toBeDefined();
expect(
updatedPackageJson.devDependencies['@nrwl/schematics']
).toBeDefined();
expect(updatedPackageJson.dependencies['@nrwl/nx']).toBeDefined();
expect(updatedPackageJson.dependencies['@ngrx/store']).toBeDefined();
expect(updatedPackageJson.dependencies['@ngrx/effects']).toBeDefined();
expect(updatedPackageJson.dependencies['@ngrx/router-store']).toBeDefined();
expect(updatedPackageJson.dependencies['@ngrx/store-devtools']).toBeDefined();
expect(
updatedPackageJson.dependencies['@ngrx/store-devtools']
).toBeDefined();

// check if angular-cli.json get merged
const updatedAngularCLIJson = JSON.parse(readFile('.angular-cli.json'));
Expand All @@ -54,9 +72,15 @@ describe('Nrwl Convert to Nx Workspace', () => {
expect(updatedAngularCLIJson.apps[0].outDir).toEqual('dist/apps/proj');
expect(updatedAngularCLIJson.apps[0].test).toEqual('../../../test.js');
expect(updatedAngularCLIJson.apps[0].tsconfig).toEqual('tsconfig.app.json');
expect(updatedAngularCLIJson.apps[0].testTsconfig).toEqual('../../../tsconfig.spec.json');
expect(updatedAngularCLIJson.apps[0].scripts[0]).toEqual('../../../node_modules/x.js');
expect(updatedAngularCLIJson.defaults.schematics.collection).toEqual('@nrwl/schematics');
expect(updatedAngularCLIJson.apps[0].testTsconfig).toEqual(
'../../../tsconfig.spec.json'
);
expect(updatedAngularCLIJson.apps[0].scripts[0]).toEqual(
'../../../node_modules/x.js'
);
expect(updatedAngularCLIJson.defaults.schematics.collection).toEqual(
'@nrwl/schematics'
);

// check if tsconfig.json get merged
const updatedTsConfig = JSON.parse(readFile('tsconfig.json'));
Expand Down Expand Up @@ -85,11 +109,15 @@ describe('Nrwl Convert to Nx Workspace', () => {
runCLI('generate workspace proj --collection=@nrwl/schematics');
// check that dependencies and devDependencies remained the same
const packageJson = JSON.parse(readFile('package.json'));
expect(packageJson.devDependencies['@nrwl/schematics']).toEqual(schematicsVersion);
expect(packageJson.devDependencies['@nrwl/schematics']).toEqual(
schematicsVersion
);
expect(packageJson.dependencies['@nrwl/nx']).toEqual(nxVersion);
expect(packageJson.dependencies['@ngrx/store']).toEqual(ngrxVersion);
expect(packageJson.dependencies['@ngrx/effects']).toEqual(ngrxVersion);
expect(packageJson.dependencies['@ngrx/router-store']).toEqual(ngrxVersion);
expect(packageJson.dependencies['@ngrx/store-devtools']).toEqual(ngrxVersion);
expect(packageJson.dependencies['@ngrx/store-devtools']).toEqual(
ngrxVersion
);
});
});
29 changes: 19 additions & 10 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const projectName: string = 'proj';
export function runNgNew(command?: string, silent?: boolean): string {
return execSync(`../node_modules/.bin/ng new proj ${command}`, {
cwd: `./tmp`,
...(silent ? {stdio: ['ignore', 'ignore', 'ignore']} : {})
...(silent ? { stdio: ['ignore', 'ignore', 'ignore'] } : {})
}).toString();
}

Expand All @@ -17,10 +17,9 @@ export function newProject(): void {
//TODO delete the try catch after 0.8.0 is released
try {
runNgNew('--collection=@nrwl/schematics --npmScope=proj', true);
} catch (e) {
}
} catch (e) {}
copyMissingPackages();
execSync('npm run postinstall', {cwd: './tmp/proj'});
execSync('npm run postinstall', { cwd: './tmp/proj' });
execSync('mv ./tmp/proj ./tmp/proj_backup');
}
execSync('cp -a ./tmp/proj_backup ./tmp/proj');
Expand All @@ -32,10 +31,9 @@ export function newBazelProject(): void {
//TODO delete the try catch after 0.8.0 is released
try {
runNgNew('--collection=@nrwl/bazel --npmScope=proj', true);
} catch (e) {
}
} catch (e) {}
copyMissingPackages();
execSync('npm run postinstall', {cwd: './tmp/proj'});
execSync('npm run postinstall', { cwd: './tmp/proj' });
execSync('mv ./tmp/proj ./tmp/proj_backup');
}
execSync('cp -a ./tmp/proj_backup ./tmp/proj');
Expand All @@ -52,7 +50,13 @@ export function createNxWorkspace(command: string): string {
}

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

Expand All @@ -72,7 +76,10 @@ export function runCLI(
cwd: `./tmp/${projectName}`
})
.toString()
.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
''
);
} catch (e) {
if (opts.silenceError) {
return e.stdout.toString();
Expand Down Expand Up @@ -107,7 +114,9 @@ export function updateFile(f: string, content: string): void {

export function checkFilesExist(...expectedFiles: string[]) {
expectedFiles.forEach(f => {
const ff = f.startsWith('/') ? f : path.join(getCwd(), 'tmp', projectName, f);
const ff = f.startsWith('/')
? f
: path.join(getCwd(), 'tmp', projectName, f);
if (!exists(ff)) {
throw new Error(`File '${ff}' does not exist`);
}
Expand Down
Loading

0 comments on commit 74d920a

Please sign in to comment.