|
@@ -3,60 +3,82 @@
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
|
const gulp = require( 'gulp' );
|
|
const gulp = require( 'gulp' );
|
|
|
|
|
+const istanbul = require( 'gulp-istanbul' );
|
|
|
const gutil = require( 'gulp-util' );
|
|
const gutil = require( 'gulp-util' );
|
|
|
const mocha = require( 'gulp-mocha' );
|
|
const mocha = require( 'gulp-mocha' );
|
|
|
const chai = require( 'chai' );
|
|
const chai = require( 'chai' );
|
|
|
const filterBy = require( 'gulp-filter-by' );
|
|
const filterBy = require( 'gulp-filter-by' );
|
|
|
const filter = require( 'gulp-filter' );
|
|
const filter = require( 'gulp-filter' );
|
|
|
const sinon = require( 'sinon' );
|
|
const sinon = require( 'sinon' );
|
|
|
-const minimist = require( 'minimist' );
|
|
|
|
|
const devTools = require( '../dev/utils/tools' );
|
|
const devTools = require( '../dev/utils/tools' );
|
|
|
const semver = require( 'semver' );
|
|
const semver = require( 'semver' );
|
|
|
|
|
+const minimist = require( 'minimist' );
|
|
|
|
|
+const buildUtils = require( '../build/utils' );
|
|
|
|
|
|
|
|
module.exports = () => {
|
|
module.exports = () => {
|
|
|
const ignoreRegexp = /\/\* ?bender-tags:.*\bbrowser-only\b.*\*\//;
|
|
const ignoreRegexp = /\/\* ?bender-tags:.*\bbrowser-only\b.*\*\//;
|
|
|
|
|
+ const options = minimist( process.argv.slice( 2 ), {
|
|
|
|
|
+ boolean: [
|
|
|
|
|
+ 'coverage'
|
|
|
|
|
+ ],
|
|
|
|
|
+
|
|
|
|
|
+ default: {
|
|
|
|
|
+ coverage: false
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
// Inject globals before running tests.
|
|
// Inject globals before running tests.
|
|
|
global.should = chai.should;
|
|
global.should = chai.should;
|
|
|
global.expect = chai.expect;
|
|
global.expect = chai.expect;
|
|
|
global.assert = chai.assert;
|
|
global.assert = chai.assert;
|
|
|
global.sinon = sinon;
|
|
global.sinon = sinon;
|
|
|
|
|
+ global.bender = { model: {}, view: {} };
|
|
|
|
|
|
|
|
const tasks = {
|
|
const tasks = {
|
|
|
- testEditor() {
|
|
|
|
|
- const options = minimist( process.argv.slice( 2 ), {
|
|
|
|
|
- boolean: [ 'node' ],
|
|
|
|
|
- default: {
|
|
|
|
|
- 'node': false
|
|
|
|
|
- }
|
|
|
|
|
- } );
|
|
|
|
|
|
|
|
|
|
- if ( options.node ) {
|
|
|
|
|
- return tasks.testInNode();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ src() {
|
|
|
|
|
+ const src = [
|
|
|
|
|
+ 'build/cjs/tests/**/*.js',
|
|
|
|
|
+ '!**/_utils/**/*.js',
|
|
|
|
|
+ '!build/cjs/tests/{ui,ui-*}/**/*.js',
|
|
|
|
|
+ '!build/cjs/tests/theme-*/**/*.js'
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ return gulp.src( src )
|
|
|
|
|
+ .pipe( tasks.skipManual() )
|
|
|
|
|
+ .pipe( tasks.skipIgnored() );
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ prepareCoverage() {
|
|
|
|
|
+ return tasks.src()
|
|
|
|
|
+ // Covering files
|
|
|
|
|
+ .pipe( istanbul() )
|
|
|
|
|
+ // Force `require` to return covered files
|
|
|
|
|
+ .pipe( istanbul.hookRequire() );
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Runs tests in Node.js environment.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @returns {Stream}
|
|
|
|
|
+ */
|
|
|
testInNode() {
|
|
testInNode() {
|
|
|
const minVersion = '6.1.0';
|
|
const minVersion = '6.1.0';
|
|
|
|
|
|
|
|
if ( semver.lt( process.version, minVersion ) ) {
|
|
if ( semver.lt( process.version, minVersion ) ) {
|
|
|
throw new gutil.PluginError( {
|
|
throw new gutil.PluginError( {
|
|
|
- plugin: 'test-editor',
|
|
|
|
|
|
|
+ plugin: 'test-node',
|
|
|
message: `Wrong Node.js version. Please use Node.js in version v${ minVersion } or higher.`
|
|
message: `Wrong Node.js version. Please use Node.js in version v${ minVersion } or higher.`
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const src = [
|
|
|
|
|
- 'build/cjs/tests/**/*.js',
|
|
|
|
|
- '!**/_utils/**/*.js',
|
|
|
|
|
- '!build/cjs/tests/{ui,ui-*}/**/*.js',
|
|
|
|
|
- '!build/cjs/tests/theme-*/**/*.js'
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ // Include global test tools.
|
|
|
|
|
+ global.bender.model = require( '../../../build/cjs/tests/engine/_utils/model.js' );
|
|
|
|
|
+ global.bender.view = require( '../../../build/cjs/tests/engine/_utils/view.js' );
|
|
|
|
|
|
|
|
- return gulp.src( src )
|
|
|
|
|
- .pipe( tasks.skipManual() )
|
|
|
|
|
- .pipe( tasks.skipIgnored() )
|
|
|
|
|
- .pipe( mocha() );
|
|
|
|
|
|
|
+ return tasks.src()
|
|
|
|
|
+ .pipe( mocha( { reporter: 'progress' } ) )
|
|
|
|
|
+ .pipe( options.coverage ? istanbul.writeReports() : buildUtils.noop() );
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -81,7 +103,13 @@ module.exports = () => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- gulp.task( 'test-editor', [ 'build:js:cjs' ], tasks.testEditor );
|
|
|
|
|
|
|
+ gulp.task( 'test-node:coverage', [ 'build:js:cjs' ], tasks.prepareCoverage );
|
|
|
|
|
+
|
|
|
|
|
+ if ( options.coverage ) {
|
|
|
|
|
+ gulp.task( 'test-node', [ 'build:js:cjs', 'test-node:coverage' ], tasks.testInNode );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ gulp.task( 'test-node', [ 'build:js:cjs' ], tasks.testInNode );
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return tasks;
|
|
return tasks;
|
|
|
};
|
|
};
|