Skip to content

Commit 3550f17

Browse files
committed
fix e2e webpack test
1 parent e16a42e commit 3550f17

File tree

6 files changed

+45
-12
lines changed

6 files changed

+45
-12
lines changed

packages/webpack/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'reflect-metadata';
2+
13
export * from './codegen'
24
export * from './plugin'
35
export {ngcLoader as default} from './loader'
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {node, ng, npm} from '../utils/process';
2+
3+
4+
export default function() {
5+
return Promise.resolve()
6+
.then(() => console.log('Environment:'))
7+
.then(() => {
8+
Object.keys(process.env).forEach(envName => {
9+
console.log(` ${envName}: ${process.env[envName].replace(/[\n\r]+/g, '\n ')}`);
10+
});
11+
})
12+
.then(() => node('--version'))
13+
.then(() => npm('--version'))
14+
.then(() => ng('version'));
15+
}

tests/e2e/setup/500-create-project.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import {gitClean, gitCommit} from '../utils/git';
99
export default function(argv: any) {
1010
let createProject = null;
1111

12-
// If we're set to reuse an existing project, just chdir to it and clean it.
12+
// This is a dangerous flag, but is useful for testing packages only.
1313
if (argv.noproject) {
1414
return Promise.resolve();
1515
} else if (argv.reuse) {
16+
// If we're set to reuse an existing project, just chdir to it and clean it.
1617
createProject = Promise.resolve()
1718
.then(() => process.chdir(argv.reuse))
1819
.then(() => gitClean());

tests/e2e/tests/packages/webpack/test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {copyAssets} from '../../../utils/assets';
2-
import {npm, exec} from '../../../utils/process';
2+
import {exec, silentNpm} from '../../../utils/process';
33
import {updateJsonFile} from '../../../utils/project';
44
import {join} from 'path';
5+
import {expectFileSizeToBeUnder} from '../../../utils/fs';
56

67

78
export default function(argv: any, skipCleaning: () => void) {
@@ -14,9 +15,10 @@ export default function(argv: any, skipCleaning: () => void) {
1415
const dist = '../../../../../dist/';
1516
json['dependencies']['@ngtools/webpack'] = join(__dirname, dist, 'webpack');
1617
}))
17-
.then(() => npm('install'))
18-
.then(() => exec('node_modules/.bin/webpack', '-p', 'webpack.config.js'))
19-
.then(() => console.log(process.cwd()))
18+
.then(() => silentNpm('install'))
19+
.then(() => exec('node_modules/.bin/webpack', '-p'))
20+
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 400000))
21+
.then(() => expectFileSizeToBeUnder('dist/0.app.main.js', 40000))
2022
.then(() => process.chdir(currentDir))
2123
.then(() => skipCleaning());
2224
}

tests/e2e/utils/fs.ts

+9
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,12 @@ export function expectFileToMatch(fileName: string, regEx: RegExp | string) {
119119
}
120120
});
121121
}
122+
123+
export function expectFileSizeToBeUnder(fileName: string, sizeInBytes: number) {
124+
return readFile(fileName)
125+
.then(content => {
126+
if (content.length > sizeInBytes) {
127+
throw new Error(`File "${fileName}" exceeded file size of "${sizeInBytes}".`);
128+
}
129+
});
130+
}

tests/e2e/utils/process.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
3131
spawnOptions['stdio'] = 'pipe';
3232
}
3333

34-
const npmProcess = child_process.spawn(cmd, args, spawnOptions);
35-
npmProcess.stdout.on('data', (data: Buffer) => {
34+
const childProcess = child_process.spawn(cmd, args, spawnOptions);
35+
childProcess.stdout.on('data', (data: Buffer) => {
3636
stdout += data.toString('utf-8');
3737
if (options.silent) {
3838
return;
@@ -42,21 +42,21 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
4242
.filter(line => line !== '')
4343
.forEach(line => console.log(' ' + line));
4444
});
45-
npmProcess.stderr.on('data', (data: Buffer) => {
45+
childProcess.stderr.on('data', (data: Buffer) => {
4646
stderr += data.toString('utf-8');
4747
data.toString('utf-8')
4848
.split(/[\n\r]+/)
4949
.filter(line => line !== '')
5050
.forEach(line => console.error(yellow(' ' + line)));
5151
});
5252

53-
_processes.push(npmProcess);
53+
_processes.push(childProcess);
5454

5555
// Create the error here so the stack shows who called this function.
5656
const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `);
5757
return new Promise((resolve, reject) => {
58-
npmProcess.on('exit', (error: any) => {
59-
_processes = _processes.filter(p => p !== npmProcess);
58+
childProcess.on('exit', (error: any) => {
59+
_processes = _processes.filter(p => p !== childProcess);
6060

6161
if (!error) {
6262
resolve(stdout);
@@ -67,7 +67,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
6767
});
6868

6969
if (options.waitForMatch) {
70-
npmProcess.stdout.on('data', (data: Buffer) => {
70+
childProcess.stdout.on('data', (data: Buffer) => {
7171
if (data.toString().match(options.waitForMatch)) {
7272
resolve(stdout);
7373
}
@@ -113,6 +113,10 @@ export function npm(...args: string[]) {
113113
return _exec({}, 'npm', args);
114114
}
115115

116+
export function node(...args: string[]) {
117+
return _exec({}, 'node', args);
118+
}
119+
116120
export function git(...args: string[]) {
117121
return _exec({}, 'git', args);
118122
}

0 commit comments

Comments
 (0)