Skip to content

Commit 4bf50f3

Browse files
committed
feat(nativescript): Add a separate zone-nativescript entrypoint
Based on the zone-node entrypoint with the timers module patching removed. Also add rudimentary support for running NativeScript tests under node.js (to avoid setting up device emulators).
1 parent ffb2ab1 commit 4bf50f3

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

Diff for: gulpfile.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ gulp.task('build/zone-node.js', ['compile-esm'], function(cb) {
7777
return generateScript('./lib/node/node.ts', 'zone-node.js', false, cb);
7878
});
7979

80+
gulp.task('build/zone-nativescript.js', ['compile-esm'], function(cb) {
81+
return generateScript('./lib/nativescript/nativescript.ts', 'zone-nativescript.js', false, cb);
82+
});
83+
8084
// Zone for the browser.
8185
gulp.task('build/zone.js', ['compile-esm'], function(cb) {
8286
return generateScript('./lib/browser/rollup-main.ts', 'zone.js', false, cb);
@@ -187,6 +191,7 @@ gulp.task('build', [
187191
'build/zone-mix.js',
188192
'build/bluebird.js',
189193
'build/bluebird.min.js',
194+
'build/zone-nativescript.js',
190195
'build/jasmine-patch.js',
191196
'build/jasmine-patch.min.js',
192197
'build/mocha-patch.js',
@@ -232,6 +237,34 @@ gulp.task('test/node', ['compile'], function(cb) {
232237
jrunner.execute();
233238
});
234239

240+
gulp.task('test/nativescript', ['compile'], function(cb) {
241+
var JasmineRunner = require('jasmine');
242+
var jrunner = new JasmineRunner();
243+
244+
var specFiles = ['build/test/nativescript_entry_point.js'];
245+
246+
jrunner.configureDefaultReporter({showColors: true});
247+
248+
jrunner.onComplete(function(passed) {
249+
if (!passed) {
250+
var err = new Error('Jasmine node tests failed.');
251+
// The stack is not useful in this context.
252+
err.showStack = false;
253+
cb(err);
254+
} else {
255+
cb();
256+
}
257+
});
258+
jrunner.print = function(value) {
259+
process.stdout.write(value);
260+
}
261+
jrunner.addReporter(new JasmineRunner.ConsoleReporter(jrunner));
262+
jrunner.projectBaseDir = __dirname;
263+
jrunner.specDir = '';
264+
jrunner.addSpecFiles(specFiles);
265+
jrunner.execute();
266+
});
267+
235268
// Check the coding standards and programming errors
236269
gulp.task('lint', () => {
237270
const tslint = require('gulp-tslint');
@@ -293,4 +326,4 @@ gulp.task('promisetest', ['build/zone-node.js'], (cb) => {
293326
cb(err);
294327
}
295328
});
296-
});
329+
});

Diff for: lib/nativescript/nativescript.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import '../zone';
10+
import {patchTimer} from '../common/timers';
11+
12+
13+
const set = 'set';
14+
const clear = 'clear';
15+
16+
// Timers
17+
patchTimer(global, set, clear, 'Timeout');
18+
patchTimer(global, set, clear, 'Interval');
19+
patchTimer(global, set, clear, 'Immediate');

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"test:single": "npm run tsc && concurrently \"npm run ws-server\" \"npm run karma-jasmine:autoclose\"",
3232
"test-dist": "concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-dist-jasmine.conf.js\"",
3333
"test-node": "gulp test/node",
34+
"test-nativescript": "gulp test/nativescript",
3435
"test-mocha": "npm run tsc && concurrently \"npm run tsc:w\" \"npm run ws-server\" \"karma start karma-build-mocha.conf.js\"",
3536
"serve": "python -m SimpleHTTPServer 8000"
3637
},

Diff for: test/nativescript_entry_point.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Must be loaded before zone loads, so that zone can detect WTF.
2+
import './wtf_mock';
3+
import './custom_error';
4+
5+
// Setup tests for Zone without microtask support
6+
import '../lib/zone';
7+
import '../lib/nativescript/nativescript';
8+
import '../lib/zone-spec/async-test';
9+
import '../lib/zone-spec/fake-async-test';
10+
import '../lib/zone-spec/long-stack-trace';
11+
import '../lib/zone-spec/proxy';
12+
import '../lib/zone-spec/sync-test';
13+
import '../lib/zone-spec/task-tracking';
14+
import '../lib/zone-spec/wtf';
15+
16+
// Setup test environment
17+
import './test-env-setup';
18+
19+
// List all tests here:
20+
import './common_tests';
21+
import './nativescript_tests';

Diff for: test/nativescript_tests.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/

0 commit comments

Comments
 (0)