Skip to content

Commit 85cf033

Browse files
authored
Updating the build/test/lint scripts to use npm instead of gulp (#79)
* Moving lint and test logic from gulpfile.js to npm * Updated documentation; Fixed a flaky unit test; Updated release package build script * Updating some comments
1 parent fc45c4f commit 85cf033

File tree

7 files changed

+101
-94
lines changed

7 files changed

+101
-94
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ lib/
77
typings/
88
coverage/
99
node_modules/
10+
.nyc_output/
1011

1112
# Real key file should not be checked in
1213
test/resources/key.json

CONTRIBUTING.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,37 +104,31 @@ follow the prompts:
104104
$ gcloud beta auth application-default login
105105
```
106106

107-
### Lint, Build, and Test
107+
### Running the Linter
108108

109109
Source files are written in [TypeScript](https://www.typescriptlang.org/) and linted using
110-
[TSLint](https://palantir.github.io/tslint/). Tests are run on the compiled JavaScript files.
111-
112-
The lint, build, and test process is kicked off via the default `gulp` task, although you can also
113-
run each task individually:
110+
[TSLint](https://palantir.github.io/tslint/). Run the following command to kick off the linter:
114111

115112
```bash
116-
$ gulp # Lint, build, and test
117-
$ gulp lint # Just lint
118-
$ gulp build # Just build
119-
$ gulp test # Just test
113+
$ npm run lint
120114
```
121115

122116
### Running Tests
123117

124118
There are two test suites: unit and integration. The unit test suite is intended to be run during
125-
development and the integration test suite is intended to be run before packaging up release
119+
development, and the integration test suite is intended to be run before packaging up release
126120
candidates.
127121

128122
To run the unit test suite:
129123

130-
```
131-
$ gulp # Lint, build, and run unit test suite
124+
```bash
125+
$ npm test # Lint and run unit test suite
132126
```
133127

134-
To run the integration test suite:
128+
If you wish to skip the linter, and only run the unit tests:
135129

136-
```
137-
$ node test/integration # Run integration test suite
130+
```bash
131+
$ npm run test:unit
138132
```
139133

140134
The integration test suite requires a service account JSON key file, and an API key for a Firebase
@@ -143,7 +137,22 @@ you do not already have one. Use a separate, dedicated project for integration t
143137
test suite makes a large number of writes to the Firebase realtime database. Download the service
144138
account key file from the "Settings > Service Accounts" page of the project, and copy it to
145139
`test/resources/key.json`. Also obtain the API key for the same project from "Settings > General",
146-
and save it to `test/resource/apikey.txt`.
140+
and save it to `test/resource/apikey.txt`. Finally, to run the integration test suite:
141+
142+
```bash
143+
$ npm run integration # Build and run integration test suite
144+
```
145+
146+
The integration test suite overwrites the security rules present in your Firebase project. You
147+
will be prompted before the overwrite takes place:
148+
149+
```
150+
Warning: This test will overwrite your project's existing Database rules.
151+
Overwrite Database rules for tests?
152+
* 'yes' to agree
153+
* 'skip' to continue without the overwrite
154+
* 'no' to cancel
155+
```
147156

148157
### Repo Organization
149158

@@ -173,6 +182,10 @@ Here are some highlights of the directory structure and notable source files
173182
* `resources/` - Provides mocks for several variables as well as mock service account keys.
174183
* `.github/` - Contribution instructions as well as issue and pull request templates.
175184
* `createReleaseTarball.sh` - Generates a new release tarball and ensures it passes all tests.
176-
* `gulpfile.js` - Defines the `gulp` tasks.
185+
* `verifyReleaseTarball.sh` - Installs and validates the release tarballs created by
186+
`createReleaseTarball.sh`.
187+
* `gulpfile.js` - Defines the `gulp` tasks necessary for building release artifacts.
177188
* `tslint.json` - TypeScript linting rules.
178189
* `tsconfig.json` - TypeScript configuration options.
190+
* `tsconfig-lint.json` - TypeScript configuration options for the linter. This simply widens
191+
the scope of `tsconfig.json` by including some test source files in the project.

createReleaseTarball.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,34 @@ if [[ $? -ne 0 ]]; then
128128
fi
129129
echo
130130

131-
echo "[INFO] Linting, building, and running unit tests..."
132-
gulp
131+
echo "[INFO] Running linter..."
132+
npm run lint
133133
if [[ $? -ne 0 ]]; then
134-
echo "Error: Failed to lint, build, and run unit tests."
134+
echo "Error: Linter failed."
135135
exit 1
136136
fi
137137
echo
138138

139-
echo "[INFO] Running integration test suite..."
140-
node test/integration
139+
echo "[INFO] Running unit tests..."
140+
npm run test:unit
141141
if [[ $? -ne 0 ]]; then
142-
echo "Error: Integration test suite failed."
142+
echo "Error: Unit tests failed."
143+
exit 1
144+
fi
145+
echo
146+
147+
echo "[INFO] Building the release package contents..."
148+
npm run build
149+
if [[ $? -ne 0 ]]; then
150+
echo "Error: Failed to build release package contents."
151+
exit 1
152+
fi
153+
echo
154+
155+
echo "[INFO] Running integration tests..."
156+
npm run test:integration -- --overwrite yes
157+
if [[ $? -ne 0 ]]; then
158+
echo "Error: Integration tests failed."
143159
exit 1
144160
fi
145161
echo

gulpfile.js

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,12 @@ var runSequence = require('run-sequence');
2828
// File I/O
2929
var fs = require('fs');
3030
var exit = require('gulp-exit');
31-
var tslint = require('gulp-tslint');
3231
var ts = require('gulp-typescript');
3332
var del = require('del');
3433
var merge = require('merge2');
3534
var header = require('gulp-header');
3635
var replace = require('gulp-replace');
3736

38-
// Testing
39-
var mocha = require('gulp-mocha');
40-
var istanbul = require('gulp-istanbul');
41-
4237

4338
/****************/
4439
/* FILE PATHS */
@@ -52,28 +47,13 @@ var paths = {
5247
'src/**/*.js'
5348
],
5449

55-
tests: [
56-
'test/unit/utils.ts',
57-
'test/unit/**/*.spec.ts',
58-
'test/resources/mocks.ts'
59-
],
60-
61-
resources: [
62-
'test/resources/*.json'
63-
],
64-
6550
build: 'lib/',
66-
67-
testBuild: '.tmp/',
68-
69-
testRunner: ['.tmp/test/unit/index.spec.js']
7051
};
7152

7253
// Create a separate project for buildProject that overrides the rootDir
7354
// This ensures that the generated production files are in their own root
7455
// rather than including both src and test in the lib dir.
7556
var buildProject = ts.createProject('tsconfig.json', {rootDir: 'src'});
76-
var testProject = ts.createProject('tsconfig.json');
7757

7858
var banner = `/*! firebase-admin v${pkg.version} */\n`;
7959

@@ -84,7 +64,6 @@ var banner = `/*! firebase-admin v${pkg.version} */\n`;
8464
gulp.task('cleanup', function() {
8565
return del([
8666
paths.build,
87-
paths.testBuild
8867
]);
8968
});
9069

@@ -122,54 +101,9 @@ gulp.task('copyTypings', function() {
122101
.pipe(gulp.dest(paths.build))
123102
});
124103

125-
// Lints the source and test files
126-
gulp.task('lint', function() {
127-
let filesToLint = _.clone(paths.src.concat(paths.tests));
128-
129-
// Don't lint the hand-crafted TypeScript typings file
130-
filesToLint.push('!src/index.d.ts');
131-
132-
return gulp.src(filesToLint)
133-
.pipe(tslint())
134-
.pipe(tslint.report({
135-
summarizeFailureOutput: true
136-
}));
137-
});
138-
139-
// Runs the test suite
140-
gulp.task('test', function() {
141-
merge(
142-
// Copy compiled source and test files
143-
gulp.src(paths.tests.concat(paths.src), {base: '.'})
144-
.pipe(testProject())
145-
.pipe(gulp.dest(paths.testBuild)),
146-
// Copy compiled database files
147-
gulp.src(paths.build + 'database/**/*')
148-
.pipe(gulp.dest(paths.testBuild + 'src/database/')),
149-
// Copy test resources
150-
gulp.src(paths.resources, {base: '.'})
151-
.pipe(gulp.dest(paths.testBuild))
152-
).on('finish', function() {
153-
return gulp.src([paths.testBuild + 'src/**/*.js', '!' + paths.testBuild + 'src/database/**/*'])
154-
.pipe(istanbul())
155-
.pipe(istanbul.hookRequire())
156-
.on('finish', function() {
157-
return gulp.src(paths.testRunner)
158-
.pipe(mocha({
159-
reporter: 'spec',
160-
timeout: 5000
161-
}))
162-
.pipe(istanbul.writeReports())
163-
.on('finish', function() {
164-
return del(paths.testBuild).then(exit);
165-
});
166-
});
167-
})
168-
});
169-
170-
// Re-runs the linter and regenerates js every time a source file changes
104+
// Regenerates js every time a source file changes
171105
gulp.task('watch', function() {
172-
gulp.watch(paths.src, ['lint', 'compile']);
106+
gulp.watch(paths.src, ['compile']);
173107
});
174108

175109
// Build task
@@ -181,7 +115,7 @@ gulp.task('build', function(done) {
181115

182116
// Default task
183117
gulp.task('default', function(done) {
184-
runSequence('lint', 'build', 'test', function(error) {
118+
runSequence('build', function(error) {
185119
done(error && error.err);
186120
});
187121
});

package.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,26 @@
66
"license": "Apache-2.0",
77
"homepage": "https://firebase.google.com/",
88
"scripts": {
9-
"test": "gulp"
9+
"build": "gulp build",
10+
"lint": "tslint --project tsconfig-lint.json --format stylish",
11+
"test": "run-s lint test:unit",
12+
"integration": "run-s build test:integration",
13+
"test:unit": "mocha test/**/*.spec.ts --compilers ts:ts-node/register",
14+
"test:integration": "node test/integration",
15+
"test:coverage": "nyc npm run test:unit"
16+
},
17+
"nyc": {
18+
"extension": [
19+
".ts"
20+
],
21+
"include": [
22+
"src"
23+
],
24+
"exclude": [
25+
"**/*.d.ts",
26+
"**/database.js"
27+
],
28+
"all": true
1029
},
1130
"keywords": [
1231
"admin",
@@ -63,13 +82,17 @@
6382
"gulp-typescript": "^3.1.2",
6483
"lodash": "^4.6.1",
6584
"merge2": "^1.0.2",
85+
"mocha": "^3.5.0",
6686
"nock": "^8.0.0",
87+
"npm-run-all": "^4.1.1",
88+
"nyc": "^11.1.0",
6789
"request": "^2.75.0",
6890
"request-promise": "^4.1.1",
6991
"run-sequence": "^1.1.5",
7092
"sinon": "^1.17.3",
7193
"sinon-chai": "^2.8.0",
7294
"tslint": "^3.5.0",
95+
"ts-node": "^3.3.0",
7396
"typescript": "^2.0.3",
7497
"typings": "^1.0.4"
7598
}

test/unit/auth/credential.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const skipAndLogWarningIfNoGcloud = () => {
7979
};
8080

8181
const ONE_HOUR_IN_SECONDS = 60 * 60;
82+
const FIVE_MINUTES_IN_SECONDS = 5 * 60;
8283

8384

8485
describe('Credential', () => {
@@ -256,7 +257,7 @@ describe('Credential', () => {
256257
const c = new RefreshTokenCredential(new RefreshToken(TEST_GCLOUD_CREDENTIALS));
257258
return c.getAccessToken().then((token) => {
258259
expect(token.access_token).to.be.a('string').and.to.not.be.empty;
259-
expect(token.expires_in).to.equal(ONE_HOUR_IN_SECONDS);
260+
expect(token.expires_in).to.greaterThan(FIVE_MINUTES_IN_SECONDS);
260261
});
261262
});
262263
});

tsconfig-lint.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"noImplicitAny": false,
6+
"lib": ["es5", "es2015.promise"],
7+
"outDir": "lib",
8+
// We manually craft typings in src/index.d.ts instead of auto-generating them.
9+
// "declaration": true,
10+
"rootDir": "."
11+
},
12+
"files": [
13+
"src/index.ts",
14+
"test/unit/utils.ts",
15+
"test/unit/**/*.spec.ts",
16+
"test/resources/mocks.ts"
17+
]
18+
}
19+

0 commit comments

Comments
 (0)