Skip to content

Commit bacecf4

Browse files
alan-agius4clydin
authored andcommitted
test(@angular-devkit/build-angular): validate that libraries source-maps are created
1 parent 32050ca commit bacecf4

File tree

3 files changed

+70
-31
lines changed

3 files changed

+70
-31
lines changed

tests/legacy-cli/e2e/tests/generate/library/library-consumption-ivy-full.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
import { writeFile } from '../../../utils/fs';
1+
import { expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
22
import { ng } from '../../../utils/process';
33
import { updateJsonFile } from '../../../utils/project';
44

55
export default async function () {
66
await ng('generate', 'library', 'my-lib');
77

8-
await writeFile('./src/app/app.module.ts', `
8+
// Force an external template
9+
await writeMultipleFiles({
10+
'projects/my-lib/src/lib/my-lib.component.html': `<p>my-lib works!</p>`,
11+
'projects/my-lib/src/lib/my-lib.component.ts': `import { Component } from '@angular/core';
12+
13+
@Component({
14+
selector: 'lib-my-lib',
15+
templateUrl: './my-lib.component.html',
16+
})
17+
export class MyLibComponent {}`,
18+
'./src/app/app.module.ts': `
919
import { BrowserModule } from '@angular/platform-browser';
1020
import { NgModule } from '@angular/core';
1121
import { MyLibModule } from 'my-lib';
@@ -24,9 +34,8 @@ export default async function () {
2434
bootstrap: [AppComponent]
2535
})
2636
export class AppModule { }
27-
`);
28-
29-
await writeFile('./src/app/app.component.ts', `
37+
`,
38+
'./src/app/app.component.ts': `
3039
import { Component } from '@angular/core';
3140
import { MyLibService } from 'my-lib';
3241
@@ -41,9 +50,8 @@ export default async function () {
4150
console.log(myLibService);
4251
}
4352
}
44-
`);
45-
46-
await writeFile('e2e/src/app.e2e-spec.ts', `
53+
`,
54+
'e2e/src/app.e2e-spec.ts': `
4755
import { browser, logging, element, by } from 'protractor';
4856
import { AppPage } from './app.po';
4957
@@ -67,7 +75,8 @@ export default async function () {
6775
}));
6876
});
6977
});
70-
`);
78+
`,
79+
});
7180

7281
// Build library in full mode (development)
7382
await ng('build', 'my-lib', '--configuration=development');
@@ -76,7 +85,7 @@ export default async function () {
7685
await runTests();
7786

7887
// JIT linking
79-
await updateJsonFile('angular.json', config => {
88+
await updateJsonFile('angular.json', (config) => {
8089
const build = config.projects['test-project'].architect.build;
8190
build.options.aot = false;
8291
build.configurations.production.buildOptimizer = false;
@@ -89,4 +98,8 @@ async function runTests(): Promise<void> {
8998
// Check that the tests succeeds both with named project, unnamed (should test app), and prod.
9099
await ng('e2e');
91100
await ng('e2e', 'test-project', '--devServerTarget=test-project:serve:production');
101+
102+
// Validate that sourcemaps for the library exists.
103+
await ng('build', '--configuration=development');
104+
await expectFileToMatch('dist/test-project/main.js.map', 'projects/my-lib/src/public-api.ts');
92105
}

tests/legacy-cli/e2e/tests/generate/library/library-consumption-ivy-partial.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
import { writeFile } from '../../../utils/fs';
1+
import { expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
22
import { ng } from '../../../utils/process';
33
import { updateJsonFile } from '../../../utils/project';
44

55
export default async function () {
66
await ng('generate', 'library', 'my-lib');
77

8-
await writeFile('./src/app/app.module.ts', `
8+
// Force an external template
9+
await writeMultipleFiles({
10+
'projects/my-lib/src/lib/my-lib.component.html': `<p>my-lib works!</p>`,
11+
'projects/my-lib/src/lib/my-lib.component.ts': `import { Component } from '@angular/core';
12+
13+
@Component({
14+
selector: 'lib-my-lib',
15+
templateUrl: './my-lib.component.html',
16+
})
17+
export class MyLibComponent {}`,
18+
'./src/app/app.module.ts': `
919
import { BrowserModule } from '@angular/platform-browser';
1020
import { NgModule } from '@angular/core';
1121
import { MyLibModule } from 'my-lib';
@@ -24,9 +34,8 @@ export default async function () {
2434
bootstrap: [AppComponent]
2535
})
2636
export class AppModule { }
27-
`);
28-
29-
await writeFile('./src/app/app.component.ts', `
37+
`,
38+
'./src/app/app.component.ts': `
3039
import { Component } from '@angular/core';
3140
import { MyLibService } from 'my-lib';
3241
@@ -41,9 +50,8 @@ export default async function () {
4150
console.log(myLibService);
4251
}
4352
}
44-
`);
45-
46-
await writeFile('e2e/src/app.e2e-spec.ts', `
53+
`,
54+
'e2e/src/app.e2e-spec.ts': `
4755
import { browser, logging, element, by } from 'protractor';
4856
import { AppPage } from './app.po';
4957
@@ -67,7 +75,8 @@ export default async function () {
6775
}));
6876
});
6977
});
70-
`);
78+
`,
79+
});
7180

7281
// Build library in partial mode (production)
7382
await ng('build', 'my-lib', '--configuration=production');
@@ -76,7 +85,7 @@ export default async function () {
7685
await runTests();
7786

7887
// JIT linking
79-
await updateJsonFile('angular.json', config => {
88+
await updateJsonFile('angular.json', (config) => {
8089
const build = config.projects['test-project'].architect.build;
8190
build.options.aot = false;
8291
build.configurations.production.buildOptimizer = false;
@@ -89,4 +98,8 @@ async function runTests(): Promise<void> {
8998
// Check that the tests succeeds both with named project, unnamed (should test app), and prod.
9099
await ng('e2e');
91100
await ng('e2e', 'test-project', '--devServerTarget=test-project:serve:production');
101+
102+
// Validate that sourcemaps for the library exists.
103+
await ng('build', '--configuration=development');
104+
await expectFileToMatch('dist/test-project/main.js.map', 'projects/my-lib/src/public-api.ts');
92105
}

tests/legacy-cli/e2e/tests/generate/library/library-consumption-ve.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1-
import { writeFile } from '../../../utils/fs';
1+
import { expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
22
import { ng } from '../../../utils/process';
33
import { updateJsonFile } from '../../../utils/project';
44

55
export default async function () {
66
await ng('generate', 'library', 'my-lib');
77

8-
await updateJsonFile('projects/my-lib/tsconfig.lib.prod.json', config => {
8+
await updateJsonFile('projects/my-lib/tsconfig.lib.prod.json', (config) => {
99
const { angularCompilerOptions = {} } = config;
1010
angularCompilerOptions.enableIvy = false;
1111
angularCompilerOptions.skipTemplateCodegen = true;
1212
angularCompilerOptions.strictMetadataEmit = true;
1313
config.angularCompilerOptions = angularCompilerOptions;
1414
});
1515

16-
await writeFile('./src/app/app.module.ts', `
16+
// Force an external template
17+
await writeMultipleFiles({
18+
'projects/my-lib/src/lib/my-lib.component.html': `<p>my-lib works!</p>`,
19+
'projects/my-lib/src/lib/my-lib.component.ts': `import { Component } from '@angular/core';
20+
21+
@Component({
22+
selector: 'lib-my-lib',
23+
templateUrl: './my-lib.component.html',
24+
})
25+
export class MyLibComponent {}`,
26+
'./src/app/app.module.ts': `
1727
import { BrowserModule } from '@angular/platform-browser';
1828
import { NgModule } from '@angular/core';
1929
import { MyLibModule } from 'my-lib';
@@ -32,9 +42,8 @@ export default async function () {
3242
bootstrap: [AppComponent]
3343
})
3444
export class AppModule { }
35-
`);
36-
37-
await writeFile('./src/app/app.component.ts', `
45+
`,
46+
'./src/app/app.component.ts': `
3847
import { Component } from '@angular/core';
3948
import { MyLibService } from 'my-lib';
4049
@@ -49,9 +58,8 @@ export default async function () {
4958
console.log(myLibService);
5059
}
5160
}
52-
`);
53-
54-
await writeFile('e2e/src/app.e2e-spec.ts', `
61+
`,
62+
'e2e/src/app.e2e-spec.ts': `
5563
import { browser, logging, element, by } from 'protractor';
5664
import { AppPage } from './app.po';
5765
@@ -75,7 +83,8 @@ export default async function () {
7583
}));
7684
});
7785
});
78-
`);
86+
`,
87+
});
7988

8089
// Build library in VE mode (production)
8190
await ng('build', 'my-lib', '--configuration=production');
@@ -84,7 +93,7 @@ export default async function () {
8493
await runTests();
8594

8695
// JIT linking
87-
await updateJsonFile('angular.json', config => {
96+
await updateJsonFile('angular.json', (config) => {
8897
const build = config.projects['test-project'].architect.build;
8998
build.options.aot = false;
9099
build.configurations.production.buildOptimizer = false;
@@ -97,4 +106,8 @@ async function runTests(): Promise<void> {
97106
// Check that the tests succeeds both with named project, unnamed (should test app), and prod.
98107
await ng('e2e');
99108
await ng('e2e', 'test-project', '--devServerTarget=test-project:serve:production');
109+
110+
// Validate that sourcemaps for the library exists.
111+
await ng('build', '--configuration=development');
112+
await expectFileToMatch('dist/test-project/main.js.map', 'projects/my-lib/src/public-api.ts');
100113
}

0 commit comments

Comments
 (0)