Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 232e494

Browse files
Run tests from within the build directory (#314)
This PR is landing as part of a transition of the tests to Typescript. PR-URL: #314
1 parent 03822e6 commit 232e494

29 files changed

+166
-103
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node_js:
55
- '6'
66
- '8'
77
script:
8-
- npm run build && ./bin/run-test.sh -c
8+
- gulp test.coverage
99
notifications:
1010
email:
1111

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ install:
1818
# Post-install test scripts.
1919
test_script:
2020
# run tests
21-
- ps: npm run build ; node_modules/.bin/mocha test --timeout 4000 --R
21+
- ps: npm run build ; node_modules/.bin/mocha build/test --timeout 4000 --R
2222

2323
# Don't actually build using MSBuild
2424
build: off

bin/run-system-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
99
-out node-team-debug-test-dfc747dacb5b.json -d
1010
fi
1111

12-
mocha system-test/test-*.js
12+
mocha build/system-test/test-*.js

bin/run-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function run {
3030
}
3131

3232
# Run test/coverage
33-
run test
33+
run build/test
3434

3535
# Conditionally publish coverage
3636
if [ "$cover" ]; then

gulpfile.js

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ const tsconfigPath = path.join(__dirname, 'tsconfig.json');
3333
const tslintPath = path.join(__dirname, 'tslint.json');
3434
const outDir = 'build';
3535
const sources = ['src/**/*.ts'];
36+
const unitTests = ['test/**/*.ts'];
37+
const systemTests = ['system-test/**/*.ts'];
38+
const allFiles = sources.concat(unitTests).concat(systemTests);
3639

3740
let exitOnError = true;
3841
function onError() {
@@ -84,15 +87,65 @@ gulp.task('compile', () => {
8487
]);
8588
});
8689

87-
gulp.task('test.compile', ['compile'], () => {
88-
// TODO: Complete this when the test files have been converted
89-
// to Typescript.
90+
gulp.task('test.system.copy', () => {
91+
return gulp.src(['system-test/**/*'])
92+
.pipe(gulp.dest(`${outDir}/system-test`));
9093
});
9194

92-
gulp.task('test.unit', ['compile'], cb => {
93-
spawn('bash', ['./bin/run-test.sh'], {
95+
gulp.task('test.system.compile', ['compile', 'test.system.copy'], () => {
96+
const tsResult = gulp.src(systemTests)
97+
.pipe(sourcemaps.init())
98+
.pipe(ts.createProject(tsconfigPath)())
99+
.on('error', onError);
100+
return merge([
101+
tsResult.js
102+
.pipe(sourcemaps.write(
103+
'.', {includeContent: false, sourceRoot: '../../system-test'}))
104+
.pipe(gulp.dest(`${outDir}/system-test`)),
105+
tsResult.js.pipe(gulp.dest(`${outDir}/system-test`))
106+
]);
107+
});
108+
109+
gulp.task('test.packagejson.copy', () => {
110+
return gulp.src(['package.json'])
111+
.pipe(gulp.dest(`${outDir}`));
112+
});
113+
114+
gulp.task('test.unit.copy', () => {
115+
return gulp.src(['test/**/*'])
116+
.pipe(gulp.dest(`${outDir}/test`));
117+
});
118+
119+
gulp.task('test.unit.compile', ['test.unit.copy', 'test.packagejson.copy', 'compile'], () => {
120+
const tsResult = gulp.src(unitTests)
121+
.pipe(sourcemaps.init())
122+
.pipe(ts.createProject(tsconfigPath)())
123+
.on('error', onError);
124+
return merge([
125+
tsResult.js
126+
.pipe(sourcemaps.write(
127+
'.', {includeContent: false, sourceRoot: '../../test'}))
128+
.pipe(gulp.dest(`${outDir}/test`)),
129+
tsResult.js.pipe(gulp.dest(`${outDir}/test`))
130+
]);
131+
});
132+
133+
function runTests(withCoverage, cb) {
134+
var args = [path.join('.', 'bin', 'run-test.sh')];
135+
if (withCoverage) {
136+
args = args.concat('-c');
137+
}
138+
spawn('bash', args, {
94139
stdio : 'inherit'
95140
}).on('close', cb);
141+
}
142+
143+
gulp.task('test.run', ['test.unit.compile', 'test.system.compile'], cb => {
144+
runTests(false, cb);
145+
});
146+
147+
gulp.task('test.coverage.run', ['test.unit.compile', 'test.system.compile'], cb => {
148+
runTests(true, cb);
96149
});
97150

98151
gulp.task('watch', () => {
@@ -102,5 +155,8 @@ gulp.task('watch', () => {
102155
return gulp.watch(sources, ['test.compile']);
103156
});
104157

105-
gulp.task('test', ['test.unit', 'test.check-format', 'test.check-lint']);
106-
gulp.task('default', ['compile']);
158+
// TODO: Enable linting and checking format after the conversion to
159+
// Typescript is complete.
160+
gulp.task('test', ['test.run']);//, 'test.check-format', 'test.check-lint']);
161+
gulp.task('test.coverage', ['test.coverage.run']);//, 'test.check-format', 'test.check-lint']);
162+
gulp.task('default', ['compile', 'test.unit.compile', 'test.system.compile']);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"util.promisify": "^1.0.0"
6565
},
6666
"scripts": {
67-
"build": "gulp compile",
67+
"build": "gulp",
6868
"changelog": "npm run build && ./bin/run-changelog.sh",
6969
"coverage": "npm run build && ./bin/run-test.sh -c",
7070
"prepare": "npm run build",

system-test/test-controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ assert.ok(
2626
'Need to have GOOGLE_APPLICATION_CREDENTIALS defined to be able to run ' +
2727
'this test');
2828

29-
var Controller = require('../build/src/controller.js').Controller;
30-
var Debuggee = require('../build/src/debuggee.js').Debuggee;
31-
var debug = require('../build/src/debug.js').Debug();
29+
var Controller = require('../src/controller.js').Controller;
30+
var Debuggee = require('../src/debuggee.js').Debuggee;
31+
var debug = require('../src/debug.js').Debug();
3232

3333

3434
describe('Controller', function() {

system-test/test-e2e.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ var _ = require('lodash'); // for _.find. Can't use ES6 yet.
2121
var cp = require('child_process');
2222
var semver = require('semver');
2323
var promisifyAll = require('@google-cloud/common').util.promisifyAll;
24-
var Debug = require('../build/src/debug.js').Debug;
24+
var Debug = require('../src/debug.js').Debug;
2525
var Debugger = require('../test/debugger.js');
2626

2727
var CLUSTER_WORKERS = 3;
2828

29-
var FILENAME = 'test/fixtures/fib.js';
29+
// TODO: Determine if this path should contain 'build'
30+
var FILENAME = 'build/test/fixtures/fib.js';
3031

3132
var delay = function(delayTimeMS) {
3233
return new Promise(function(resolve, reject) {

test/fixtures/fib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function fib(n) {
2424
const nocks = require('../nocks.js');
2525
nocks.projectId('fake-project-id');
2626

27-
var debuglet = require('../..').start({
27+
var debuglet = require('../../..').start({
2828
debug: {
2929
logLevel: 2,
3030
maxLogsPerSecond: 2,
File renamed without changes.

0 commit comments

Comments
 (0)