Skip to content

Commit

Permalink
fix(schematics): fix format:write --libs-and-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Feb 28, 2018
1 parent b3ca2ee commit feeaba1
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 123 deletions.
23 changes: 18 additions & 5 deletions e2e/schematics/command-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('Command line', () => {
() => {
newProject();
newApp('myapp');
newLib('mylib');
updateFile(
'apps/myapp/src/main.ts',
`
Expand All @@ -135,14 +136,26 @@ describe('Command line', () => {
`
);

updateFile(
'libs/mylib/index.ts',
`
const x = 1111;
`
);
updateFile(
'libs/mylib/src/mylib.module.ts',
`
const y = 1111;
`
);

try {
// this will group it by app, so all three files will be "marked"
runCommand('npm run -s format:check -- --files="apps/myapp/src/app/app.module.ts" --libs-and-apps');
// 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');
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('libs/mylib/index.ts');
expect(e.stdout.toString()).toContain('libs/mylib/src/mylib.module.ts');
}

try {
Expand Down
155 changes: 91 additions & 64 deletions packages/schematics/src/command-line/affected-apps.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { affectedApps, dependencies } from './affected-apps';
import {affectedApps, dependencies, DependencyType, ProjectType, touchedProjects} from './affected-apps';

describe('Calculates Dependencies Between Apps and Libs', () => {
describe('dependencies', () => {
Expand All @@ -8,19 +8,21 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'app1',
root: '',
files: [],
isApp: true
type: ProjectType.app
},
{
name: 'app2',
root: '',
files: [],
isApp: true
type: ProjectType.app
}
],
() => null
);

expect(deps).toEqual({ app1: ['app1'], app2: ['app2'] });
expect(deps).toEqual({ app1: [], app2: [] });
});

it('should infer deps between projects based on imports', () => {
Expand All @@ -29,18 +31,21 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'app1',
root: '',
files: ['app1.ts'],
isApp: true
type: ProjectType.app
},
{
name: 'lib1',
root: '',
files: ['lib1.ts'],
isApp: false
type: ProjectType.lib
},
{
name: 'lib2',
root: '',
files: ['lib2.ts'],
isApp: false
type: ProjectType.lib
}
],
file => {
Expand All @@ -58,44 +63,13 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
}
);

expect(deps).toEqual({ app1: ['app1', 'lib1', 'lib2'], lib1: ['lib1', 'lib2'], lib2: ['lib2'] });
});

it('should infer transitive deps between projects', () => {
const deps = dependencies(
'nrwl',
[
{
name: 'app1',
files: ['app1.ts'],
isApp: true
},
{
name: 'lib1',
files: ['lib1.ts'],
isApp: false
},
{
name: 'lib2',
files: ['lib2.ts'],
isApp: false
}
],
file => {
switch (file) {
case 'app1.ts':
return `
import '@nrwl/lib1';
`;
case 'lib1.ts':
return `import '@nrwl/lib2'`;
case 'lib2.ts':
return '';
}
}
);

expect(deps).toEqual({ app1: ['app1', 'lib1', 'lib2'], lib1: ['lib1', 'lib2'], lib2: ['lib2'] });
expect(deps).toEqual({
app1: [
{projectName: 'lib1', type: DependencyType.es6Import},
{projectName: 'lib2', type: DependencyType.es6Import}
],
lib1: [{projectName: 'lib2', type: DependencyType.es6Import}], lib2: []
});
});

it('should infer dependencies expressed via loadChildren', () => {
Expand All @@ -104,18 +78,21 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'app1',
root: '',
files: ['app1.ts'],
isApp: true
type: ProjectType.app
},
{
name: 'lib1',
root: '',
files: ['lib1.ts'],
isApp: false
type: ProjectType.lib
},
{
name: 'lib2',
root: '',
files: ['lib2.ts'],
isApp: false
type: ProjectType.lib
}
],
file => {
Expand All @@ -135,7 +112,8 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
}
);

expect(deps).toEqual({ app1: ['app1', 'lib1', 'lib2'], lib1: ['lib1'], lib2: ['lib2'] });
expect(deps).toEqual({ app1: [{projectName: 'lib1', type: DependencyType.loadChildren},
{projectName: 'lib2', type: DependencyType.loadChildren}], lib1: [], lib2: [] });
});

it('should handle non-ts files', () => {
Expand All @@ -144,14 +122,15 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'app1',
root: '',
files: ['index.html'],
isApp: true
type: ProjectType.app
}
],
() => null
);

expect(deps).toEqual({ app1: ['app1'] });
expect(deps).toEqual({ app1: [] });
});

it('should handle projects with the names starting with the same string', () => {
Expand All @@ -160,13 +139,15 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'aa',
root: '',
files: ['aa.ts'],
isApp: true
type: ProjectType.app
},
{
name: 'aa/bb',
root: '',
files: ['bb.ts'],
isApp: true
type: ProjectType.app
}
],
file => {
Expand All @@ -179,7 +160,7 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
}
);

expect(deps).toEqual({ aa: ['aa', 'aa/bb'], 'aa/bb': ['aa/bb'] });
expect(deps).toEqual({ aa: [{projectName: 'aa/bb', type: DependencyType.es6Import}], 'aa/bb': [] });
});
});

Expand All @@ -190,23 +171,27 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'app1',
root: '',
files: ['app1.ts'],
isApp: true
type: ProjectType.app
},
{
name: 'app2',
root: '',
files: ['app2.ts'],
isApp: true
type: ProjectType.app
},
{
name: 'lib1',
root: '',
files: ['lib1.ts'],
isApp: false
type: ProjectType.lib
},
{
name: 'lib2',
root: '',
files: ['lib2.ts'],
isApp: false
type: ProjectType.lib
}
],
file => {
Expand Down Expand Up @@ -235,18 +220,21 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'app1',
root: '',
files: ['app1.ts'],
isApp: true
type: ProjectType.app
},
{
name: 'app2',
root: '',
files: ['app2.ts'],
isApp: true
type: ProjectType.app
},
{
name: 'lib1',
root: '',
files: ['lib1.ts'],
isApp: false
type: ProjectType.lib
}
],
file => {
Expand All @@ -273,8 +261,9 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'app1',
root: '',
files: ['one\\app1.ts', 'two/app1.ts'],
isApp: true
type: ProjectType.app
}
],
file => {
Expand All @@ -297,13 +286,15 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
[
{
name: 'app1',
root: '',
files: ['app1.ts'],
isApp: true
type: ProjectType.app
},
{
name: 'app2',
root: '',
files: ['app2.ts'],
isApp: true
type: ProjectType.app
}
],
file => {
Expand All @@ -320,4 +311,40 @@ describe('Calculates Dependencies Between Apps and Libs', () => {
expect(affected).toEqual(['app2', 'app1']);
});
});

describe('touchedProjects', () => {
it('should return the list of touchedProjects', () => {
const tp = touchedProjects(
[
{
name: 'app1',
root: '',
files: ['app1.ts'],
type: ProjectType.app
},
{
name: 'app2',
root: '',
files: ['app2.ts'],
type: ProjectType.app
},
{
name: 'lib1',
root: '',
files: ['lib1.ts'],
type: ProjectType.lib
},
{
name: 'lib2',
root: '',
files: ['lib2.ts'],
type: ProjectType.lib
}
],
['lib2.ts', 'app2.ts', 'package.json']
);

expect(tp).toEqual(['lib2', 'app2', null]);
});
});
});
Loading

0 comments on commit feeaba1

Please sign in to comment.