Skip to content

Commit e93d45d

Browse files
committed
test(typings): add integration test to verify typings setup is correct
1 parent 648666f commit e93d45d

File tree

6 files changed

+127
-3
lines changed

6 files changed

+127
-3
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
sudo: false
33
node_js:
4-
- '5.4.1'
4+
- '6'
55

66
addons:
77
firefox: latest
@@ -32,6 +32,8 @@ script:
3232
- ./node_modules/.bin/karma start --single-run --browsers Firefox --reporters mocha
3333
# Make sure the build that ships to npm builds without errors
3434
- npm run build_npm
35+
# Run integration test to make sure our typings are correct for user-land.
36+
- node tools/run-typings-test.js
3537
# Can't run until https://github.com/angular/protractor/issues/2784 is resolved
3638
#- ./node_modules/.bin/protractor protractor.conf.js --browser firefox
3739

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build_npm": "rm -rf dist && ngc -p tsconfig.publish.es6.json && rollup -c rollup.publish.config.js && npm run postbuild_npm",
1515
"build_e2e": "rm -rf dist-test && npm run build && tsc -p test/ && cp test/e2e/firebase_object/index.html dist-test/e2e/firebase_object/ && cp test/e2e/firebase_list/index.html dist-test/e2e/firebase_list/ && cp test/e2e/auth/index.html dist-test/e2e/auth/",
1616
"postbuild_npm": "cp package.json README.md .npmignore dist/ && npm run rewrite_npm_package",
17-
"rewrite_npm_package": "node --harmony_destructuring tools/rewrite-published-package.js",
17+
"rewrite_npm_package": "node tools/rewrite-published-package.js",
1818
"e2e_test": "webdriver-manager update && npm run build_e2e && protractor",
1919
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"
2020
},
@@ -39,13 +39,13 @@
3939
"@angular/core": "^2.0.0",
4040
"@angular/platform-browser": "^2.0.0",
4141
"@angular/platform-browser-dynamic": "^2.0.0",
42-
"@types/request": "0.0.30",
4342
"firebase": "3.3.0",
4443
"rxjs": "5.0.0-beta.12"
4544
},
4645
"devDependencies": {
4746
"@angular/compiler-cli": "^0.5.0",
4847
"@angular/platform-server": "^2.0.0-rc.5",
48+
"@types/request": "0.0.30",
4949
"concurrently": "^2.2.0",
5050
"conventional-changelog-cli": "^1.2.0",
5151
"es6-module-loader": "^0.17.10",
@@ -64,9 +64,11 @@
6464
"karma-jasmine": "^0.3.6",
6565
"karma-mocha-reporter": "^2.0.2",
6666
"karma-systemjs": "^0.10.0",
67+
"ncp": "^2.0.0",
6768
"parse5": "^1.3.2",
6869
"protractor": "3.0.0",
6970
"reflect-metadata": "0.1.2",
71+
"rimraf": "^2.5.4",
7072
"rollup": "^0.35.11",
7173
"rollup-watch": "^2.5.0",
7274
"systemjs": "^0.19.16",

test/typings-test/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* This file just imports from a path that was previously known to having
3+
* typings errors because it relied on an ambient namespace for firebase,
4+
* which wouldn't necessarily have been loaded.
5+
*/
6+
7+
import {FirebaseSdkAuthBackend} from 'angularfire2/auth/firebase_sdk_auth_backend';
8+
9+
const Backend = FirebaseSdkAuthBackend;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "typings-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"angularfire2": "file:{{ANGULARFIRE_VERSION}}",
7+
"firebase": "{{FIREBASE_VERSION}}",
8+
"@angular/common": "{{ANGULAR_VERSION}}",
9+
"@angular/compiler": "{{ANGULAR_VERSION}}",
10+
"@angular/core": "{{ANGULAR_VERSION}}",
11+
"@angular/platform-browser": "{{ANGULAR_VERSION}}",
12+
"@angular/platform-browser-dynamic": "{{ANGULAR_VERSION}}",
13+
"zone.js": "{{ZONE_VERSION}}",
14+
"rxjs": "{{RXJS_VERSION}}",
15+
"typescript": "{{TYPESCRIPT_VERSION}}"
16+
}
17+
}

test/typings-test/tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"emitDecoratorMetadata": true,
4+
"experimentalDecorators": true,
5+
"lib": ["es6", "dom"],
6+
"module": "es6",
7+
"target": "es5",
8+
"moduleResolution": "node",
9+
"noImplicitAny": true,
10+
"skipLibCheck": false,
11+
"skipDefaultLibCheck": false,
12+
"noEmit": true
13+
},
14+
"files": [
15+
"index.ts"
16+
]
17+
}

tools/run-typings-test.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* This file uses the test project at test/typings-test to validate
3+
* that AngularFire typings don't produce errors in user code.
4+
*
5+
* 1. Create a temp directory to copy the test project
6+
* 2. Create a package.json based on test-project/package.sample.json,
7+
* using versions from the project's root package.json.
8+
* 3. NPM install inside the temporary project directory
9+
* 4. Run TSC against the project's local tsconfig.json and local node_modules
10+
* 5.
11+
*/
12+
const fs = require('fs');
13+
const path = require('path');
14+
const ncp = require('ncp');
15+
const rimraf = require('rimraf');
16+
const child_process = require('child_process');
17+
const pathToTestSrcFolder = path.resolve(__dirname, '../test/typings-test/');
18+
const binaryPath = path.resolve(__dirname, '../node_modules/.bin')
19+
const rootPackage = require(path.resolve(__dirname, '../package.json'));
20+
21+
const startingCwd = process.cwd();
22+
23+
const pathToTestFolder = fs.mkdtempSync('/tmp/typings-test-');
24+
25+
process.chdir(pathToTestFolder)
26+
27+
ncp(pathToTestSrcFolder, pathToTestFolder, () => {
28+
const samplePackage = require(`${pathToTestFolder}/package.sample.json`);
29+
30+
fs.writeFileSync(`${pathToTestFolder}/package.json`, JSON.stringify(samplePackage, null, 2)
31+
.replace('{{ANGULARFIRE_VERSION}}', path.resolve(__dirname, '../dist'))
32+
.replace('{{FIREBASE_VERSION}}', rootPackage.dependencies.firebase)
33+
.replace('{{RXJS_VERSION}}', rootPackage.dependencies.rxjs)
34+
.replace('{{ZONE_VERSION}}', rootPackage.devDependencies['zone.js'])
35+
.replace('{{TYPESCRIPT_VERSION}}', rootPackage.devDependencies.typescript)
36+
.replace(/\{\{ANGULAR_VERSION\}\}/g, rootPackage.dependencies['@angular/core']));
37+
38+
spawnIt('npm', ['install'])
39+
.then(_ => spawnIt(`${pathToTestFolder}/node_modules/.bin/tsc`, ['--version']))
40+
.then(_ => new Promise((res, rej) => {
41+
child_process.exec(`${pathToTestFolder}/node_modules/.bin/tsc --diagnostics -p ${pathToTestFolder}/tsconfig.json`, (err, stdout, stderr) => {
42+
console.log(stdout);
43+
if (err) {
44+
rej(1);
45+
} else {
46+
res();
47+
}
48+
});
49+
}))
50+
.catch(_ => {
51+
// resolve with exit code 1
52+
return Promise.resolve(1)
53+
})
54+
.then(cleanup)
55+
.then(code => process.exit(code || 0));
56+
})
57+
58+
function spawnIt(program, args) {
59+
console.log('-----------------------------------');
60+
console.log(program, (args && args.join(' ')) || '');
61+
console.log('-----------------------------------');
62+
return new Promise((res, rej) => {
63+
child_process.spawn(program, args, {
64+
cwd: pathToTestFolder,
65+
stdio: 'inherit'
66+
})
67+
.on('close', (code) => {
68+
if (code) return rej(code);
69+
res();
70+
})
71+
});
72+
}
73+
74+
function cleanup (val) {
75+
rimraf.sync(pathToTestFolder);
76+
return val;
77+
}

0 commit comments

Comments
 (0)