Skip to content

Commit

Permalink
test(@angular-devkit/build-angular): validate that libraries source-m…
Browse files Browse the repository at this point in the history
…aps are created
  • Loading branch information
alan-agius4 authored and clydin committed Jul 6, 2021
1 parent 32050ca commit bacecf4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { writeFile } from '../../../utils/fs';
import { expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
import { ng } from '../../../utils/process';
import { updateJsonFile } from '../../../utils/project';

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

await writeFile('./src/app/app.module.ts', `
// Force an external template
await writeMultipleFiles({
'projects/my-lib/src/lib/my-lib.component.html': `<p>my-lib works!</p>`,
'projects/my-lib/src/lib/my-lib.component.ts': `import { Component } from '@angular/core';
@Component({
selector: 'lib-my-lib',
templateUrl: './my-lib.component.html',
})
export class MyLibComponent {}`,
'./src/app/app.module.ts': `
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MyLibModule } from 'my-lib';
Expand All @@ -24,9 +34,8 @@ export default async function () {
bootstrap: [AppComponent]
})
export class AppModule { }
`);

await writeFile('./src/app/app.component.ts', `
`,
'./src/app/app.component.ts': `
import { Component } from '@angular/core';
import { MyLibService } from 'my-lib';
Expand All @@ -41,9 +50,8 @@ export default async function () {
console.log(myLibService);
}
}
`);

await writeFile('e2e/src/app.e2e-spec.ts', `
`,
'e2e/src/app.e2e-spec.ts': `
import { browser, logging, element, by } from 'protractor';
import { AppPage } from './app.po';
Expand All @@ -67,7 +75,8 @@ export default async function () {
}));
});
});
`);
`,
});

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

// JIT linking
await updateJsonFile('angular.json', config => {
await updateJsonFile('angular.json', (config) => {
const build = config.projects['test-project'].architect.build;
build.options.aot = false;
build.configurations.production.buildOptimizer = false;
Expand All @@ -89,4 +98,8 @@ async function runTests(): Promise<void> {
// Check that the tests succeeds both with named project, unnamed (should test app), and prod.
await ng('e2e');
await ng('e2e', 'test-project', '--devServerTarget=test-project:serve:production');

// Validate that sourcemaps for the library exists.
await ng('build', '--configuration=development');
await expectFileToMatch('dist/test-project/main.js.map', 'projects/my-lib/src/public-api.ts');
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { writeFile } from '../../../utils/fs';
import { expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
import { ng } from '../../../utils/process';
import { updateJsonFile } from '../../../utils/project';

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

await writeFile('./src/app/app.module.ts', `
// Force an external template
await writeMultipleFiles({
'projects/my-lib/src/lib/my-lib.component.html': `<p>my-lib works!</p>`,
'projects/my-lib/src/lib/my-lib.component.ts': `import { Component } from '@angular/core';
@Component({
selector: 'lib-my-lib',
templateUrl: './my-lib.component.html',
})
export class MyLibComponent {}`,
'./src/app/app.module.ts': `
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MyLibModule } from 'my-lib';
Expand All @@ -24,9 +34,8 @@ export default async function () {
bootstrap: [AppComponent]
})
export class AppModule { }
`);

await writeFile('./src/app/app.component.ts', `
`,
'./src/app/app.component.ts': `
import { Component } from '@angular/core';
import { MyLibService } from 'my-lib';
Expand All @@ -41,9 +50,8 @@ export default async function () {
console.log(myLibService);
}
}
`);

await writeFile('e2e/src/app.e2e-spec.ts', `
`,
'e2e/src/app.e2e-spec.ts': `
import { browser, logging, element, by } from 'protractor';
import { AppPage } from './app.po';
Expand All @@ -67,7 +75,8 @@ export default async function () {
}));
});
});
`);
`,
});

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

// JIT linking
await updateJsonFile('angular.json', config => {
await updateJsonFile('angular.json', (config) => {
const build = config.projects['test-project'].architect.build;
build.options.aot = false;
build.configurations.production.buildOptimizer = false;
Expand All @@ -89,4 +98,8 @@ async function runTests(): Promise<void> {
// Check that the tests succeeds both with named project, unnamed (should test app), and prod.
await ng('e2e');
await ng('e2e', 'test-project', '--devServerTarget=test-project:serve:production');

// Validate that sourcemaps for the library exists.
await ng('build', '--configuration=development');
await expectFileToMatch('dist/test-project/main.js.map', 'projects/my-lib/src/public-api.ts');
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { writeFile } from '../../../utils/fs';
import { expectFileToMatch, writeMultipleFiles } from '../../../utils/fs';
import { ng } from '../../../utils/process';
import { updateJsonFile } from '../../../utils/project';

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

await updateJsonFile('projects/my-lib/tsconfig.lib.prod.json', config => {
await updateJsonFile('projects/my-lib/tsconfig.lib.prod.json', (config) => {
const { angularCompilerOptions = {} } = config;
angularCompilerOptions.enableIvy = false;
angularCompilerOptions.skipTemplateCodegen = true;
angularCompilerOptions.strictMetadataEmit = true;
config.angularCompilerOptions = angularCompilerOptions;
});

await writeFile('./src/app/app.module.ts', `
// Force an external template
await writeMultipleFiles({
'projects/my-lib/src/lib/my-lib.component.html': `<p>my-lib works!</p>`,
'projects/my-lib/src/lib/my-lib.component.ts': `import { Component } from '@angular/core';
@Component({
selector: 'lib-my-lib',
templateUrl: './my-lib.component.html',
})
export class MyLibComponent {}`,
'./src/app/app.module.ts': `
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MyLibModule } from 'my-lib';
Expand All @@ -32,9 +42,8 @@ export default async function () {
bootstrap: [AppComponent]
})
export class AppModule { }
`);

await writeFile('./src/app/app.component.ts', `
`,
'./src/app/app.component.ts': `
import { Component } from '@angular/core';
import { MyLibService } from 'my-lib';
Expand All @@ -49,9 +58,8 @@ export default async function () {
console.log(myLibService);
}
}
`);

await writeFile('e2e/src/app.e2e-spec.ts', `
`,
'e2e/src/app.e2e-spec.ts': `
import { browser, logging, element, by } from 'protractor';
import { AppPage } from './app.po';
Expand All @@ -75,7 +83,8 @@ export default async function () {
}));
});
});
`);
`,
});

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

// JIT linking
await updateJsonFile('angular.json', config => {
await updateJsonFile('angular.json', (config) => {
const build = config.projects['test-project'].architect.build;
build.options.aot = false;
build.configurations.production.buildOptimizer = false;
Expand All @@ -97,4 +106,8 @@ async function runTests(): Promise<void> {
// Check that the tests succeeds both with named project, unnamed (should test app), and prod.
await ng('e2e');
await ng('e2e', 'test-project', '--devServerTarget=test-project:serve:production');

// Validate that sourcemaps for the library exists.
await ng('build', '--configuration=development');
await expectFileToMatch('dist/test-project/main.js.map', 'projects/my-lib/src/public-api.ts');
}

0 comments on commit bacecf4

Please sign in to comment.