8000 test(e2e): add end-to-end tests for building with mobile flag · mikebellcoder/angular-cli@4ea2ee9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ea2ee9

Browse files
committed
test(e2e): add end-to-end tests for building with mobile flag
1 parent 72bc9d9 commit 4ea2ee9

File tree

3 files changed

+68
-10
lines changed

3 files changed

+68
-10
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ env:
66
matrix:
77
- NODE_VERSION=5 SCRIPT=lint
88
- NODE_VERSION=5 SCRIPT=test
9+
- NODE_VERSION=5 TARGET=mobile SCRIPT=mobile_test
910
os:
1011
- linux
1112
- osx
1213
matrix:
1314
exclude:
1415
- os: osx
1516
env: NODE_VERSION=5 SCRIPT=lint
17+
- os: osx
18+
env: NODE_VERSION=5 TARGET=mobile SCRIPT=mobile_test
1619

1720
script:
1821
- npm run-script $SCRIPT
@@ -26,6 +29,7 @@ before_install:
2629
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0; fi
2730
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh -e /etc/init.d/xvfb start; fi
2831
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CHROME_BIN=chromium-browser; fi
32+
- if [[ "$TARGET" == "mobile" ]]; then export MOBILE_TEST=true; fi
2933
- nvm install $NODE_VERSION
3034
- npm config set spin false
3135
- npm config set progress false

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"keywords": [],
1111
"scripts": {
1212
"test": "node tests/runner",
13+
"mobile_test": "mocha tests/e2e/e2e_workflow.spec.js",
1314
"lint": "eslint ."
1415
},
1516
"repository": {

tests/e2e/e2e_workflow.spec.js

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var treeKill = require('tree-kill');
1111
var child_process = require('child_process');
1212
var ng = require('../helpers/ng');
1313
var root = path.join(process.cwd(), 'tmp');
14+
var repoPkgJson = require('../../package.json');
1415

1516
function existsSync(path) {
1617
try {
@@ -22,6 +23,8 @@ function existsSync(path) {
2223
}
2324

2425
const ngBin = `node ${path.join(process.cwd(), 'bin', 'ng')}`;
26+
const it_mobile = isMobileTest() ? it : function() {};
27+
const it_not_mobile = isMobileTest() ? function() {} : it;
2528

2629
describe('Basic end-to-end Workflow', function () {
2730
before(conf.setup);
@@ -36,20 +39,35 @@ describe('Basic end-to-end Workflow', function () {
3639
testArgs.push('Chrome_travis_ci');
3740
}
3841

42+
43+
// We don't want to use npm link because then npm dependencies
44+
// that only exist in the project will not be accessible to CLI
45+
// This is particularly problematic for --mobile, which uses Universal
46+
// libs as part of the build process.
47+
// Instead, we'll pack CLI as a tarball
3948
it('Installs angular-cli correctly', function () {
4049
this.timeout(300000);
4150

42-
sh.exec('npm link', { silent: true });
51+
sh.exec('npm pack', { silent: true });
52+
expect(existsSync(path.join(process.cwd(), `angular-cli-${repoPkgJson.version}.tgz`)));
4353
return tmp.setup('./tmp').then(function () {
4454
process.chdir('./tmp');
45-
expect(existsSync(path.join(process.cwd(), 'bin', 'ng')));
4655
});
4756
});
4857

58+
4959
it('Can create new project using `ng new test-project`', function () {
5060
this.timeout(4200000);
51-
52-
return ng(['new', 'test-project', '--link-cli=true']).then(function () {
61+
let args = ['--skip-npm'];
62+
// If testing in the mobile matrix on Travis, create project with mobile flag
63+
if (isMobileTest()) {
64+
args = args.concat(['--mobile']);
65+
}
66+
return ng(['new', 'test-project'].concat(args)).then(function () {
67+
// Install Angular CLI from packed version
68+
let tarball = path.resolve(root, `../angular-cli-${repoPkgJson.version}.tgz`);
69+
sh.exec(`npm install && npm install ${tarball}`);
70+
sh.exec(`rm ${tarball}`);
5371
expect(existsSync(path.join(root, 'test-project')));
5472
});
5573
});
@@ -66,14 +84,32 @@ describe('Basic end-to-end Workflow', function () {
6684
// stuck to the first build done
6785
sh.exec(`${ngBin} build -prod`);
6886
expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true);
69-
var mainBundlePath = path.join(process.cwd(), 'dist', 'main.js');
70-
var mainBundleContent = fs.readFileSync(mainBundlePath, { encoding: 'utf8' });
71-
// production: true minimized turns into production:!0
72-
expect(mainBundleContent).to.include('production:!0');
87+
if (!isMobileTest()) {
88+
var mainBundlePath = path.join(process.cwd(), 'dist', 'main.js');
89+
var mainBundleContent = fs.readFileSync(mainBundlePath, { encoding: 'utf8' });
90+
// production: true minimized turns into production:!0
91+
expect(mainBundleContent).to.include('production:!0');
92+
}
93+
7394
// Also does not create new things in GIT.
7495
expect(sh.exec('git status --porcelain').output).to.be.equal(undefined);
7596
});
7697

98+
it_mobile('Enables mobile-specific production features', () => {
99+
let index = fs.readFileSync(path.join(process.cwd(), 'dist/index.html'), 'utf-8');
100+
// Service Worker
101+
expect(index.includes('if (\'serviceWorker\' in navigator) {')).to.be.equal(true);
102+
expect(existsSync(path.join(process.cwd(), 'dist/worker.js'))).to.be.equal(true);
103+
104+
// Asynchronous bundle
105+
expect(index.includes('<script src="/app-concat.js" async=""></script>')).to.be.equal(true);
106+
expect(existsSync(path.join(process.cwd(), 'dist/app-concat.js'))).to.be.equal(true);
107+
108+
// App Manifest
109+
expect(index.includes('<link rel="manifest" href="/manifest.webapp">')).to.be.equal(true);
110+
expect(existsSync(path.join(process.cwd(), 'dist/manifest.webapp'))).to.be.equal(true);
111+
});
112+
77113
it('Can run `ng build` in created project', function () {
78114
this.timeout(420000);
79115

@@ -95,6 +131,17 @@ describe('Basic end-to-end Workflow', function () {
95131
});
96132
});
97133

134+
it_mobile('Does not include mobile prod features', () => {
135+
let index = fs.readFileSync(path.join(process.cwd(), 'dist/index.html'), 'utf-8');
136+
// Service Worker
137+
expect(index.includes('if (\'serviceWorker\' in navigator) {')).to.be.equal(false);
138+
expect(existsSync(path.join(process.cwd(), 'dist/worker.js'))).to.be.equal(false);
139+
140+
// Asynchronous bundle
141+
expect(index.includes('<script src="/app-concat.js" async></script>')).to.be.equal(false);
142+
expect(existsSync(path.join(process.cwd(), 'dist/app-concat.js'))).to.be.equal(false);
143+
});
144+
98145
it('lints', () => {
99146
this.timeout(420000);
100147

@@ -393,7 +440,9 @@ describe('Basic end-to-end Workflow', function () {
393440
});
394441
});
395442

396-
it('Turn on `noImplicitAny` in tsconfig.json and rebuild', function () {
443+
// This test causes complications with path resolution in TS broccoli plugin,
444+
// and isn't mobile specific
445+
it_not_mobile('Turn on `noImplicitAny` in tsconfig.json and rebuild', function () {
397446
this.timeout(420000);
398447

399448
const configFilePath = path.join(process.cwd(), 'src', 'tsconfig.json');
@@ -410,7 +459,7 @@ describe('Basic end-to-end Workflow', function () {
410459
});
411460
});
412461

413-
it('Turn on path mapping in tsconfig.json and rebuild', function () {
462+
it_not_mobile('Turn on path mapping in tsconfig.json and rebuild', function () {
414463
this.timeout(420000);
415464

416465
const configFilePath = path.join(process.cwd(), 'src', 'tsconfig.json');
@@ -485,3 +534,7 @@ describe('Basic end-to-end Workflow', function () {
485534
});
486535
});
487536
});
537+
538+
function isMobileTest() {
539+
return !!process.env['MOBILE_TEST'];
540+
}

0 commit comments

Comments
 (0)
0