Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test gulp tasks #545

Merged
merged 2 commits into from
Dec 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "0.12"
- "0.10"
- "node"
- "lts/*"
notifications:
email: false
151 changes: 67 additions & 84 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
var gulp = require('gulp');
var rimraf = require('rimraf');
var fs = require('fs');
var path = require('path');
var mergeStream = require('merge-stream');
var ts = require('./release/main');

var plumber = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var header = require('gulp-header');
var diff = require('gulp-diff');

var tsVersions = {
const gulp = require('gulp');
const rimraf = require('rimraf');
const fs = require('fs');
const path = require('path');
const mergeStream = require('merge-stream');
const ts = require('./release/main');

const plumber = require('gulp-plumber');
const diff = require('gulp-diff');

const tsVersions = {
dev: './typescript/dev',
release23: './typescript/2.3',
};
Expand All @@ -24,16 +21,16 @@ function createProject() {
return ts.createProject('lib/tsconfig.json');
}

var tsProject = createProject();
const tsProject = createProject();

var paths = {
const paths = {
scripts: ['lib/**.ts'],
definitionTypeScript: [findTSDefinition('typescript')],
releaseBeta: 'release-2',
release: 'release'
};

var tests = fs.readdirSync(path.join(__dirname, 'test')).filter(function(dir) {
const tests = fs.readdirSync(path.join(__dirname, 'test')).filter(function(dir) {
return dir !== 'baselines' && dir !== 'output' && dir.substr(0, 1) !== '.';
});

Expand All @@ -50,7 +47,7 @@ gulp.task('clean-release', function(cb) {

// Compile sources
gulp.task('scripts', ['clean'], function() {
var tsResult = gulp.src(paths.scripts.concat(paths.definitionTypeScript))
const tsResult = gulp.src(paths.scripts.concat(paths.definitionTypeScript))
.pipe(tsProject());

return mergeStream(tsResult.js, tsResult.dts)
Expand All @@ -77,89 +74,75 @@ gulp.task('typecheck', ['typecheck-dev', 'typecheck-2.3']);
// Tests

// We run every test on multiple typescript versions:
var libs = [
const libs = [
['2.4', undefined],
['2.3', require(tsVersions.release23)],
['dev', require(tsVersions.dev)]
];

// helper function for running a test.
function runTest(name, callback) {
var newTS = require('./release-2/main');
var test = require('./test/' + name + '/gulptask.js');

var done = 0;

fs.mkdirSync('test/output/' + name);
for (var i = 0; i < libs.length; i++) {
(function(i) {
var lib = libs[i];
var output = 'test/output/' + name + '/' + lib[0] + '/';
var errors = [];
var finishInfo;
var reporter = {
error: function(err) {
(function() {
if (path.sep === '\\') { //filenames embedded in error output contain OS-dependent path separators
var colon = err.message.indexOf(":");
if (colon === -1 || !err.diagnostic || err.message.indexOf(path.sep) === -1) {
return;
}

var fileName = err.message.slice(0, colon);
var detail = err.message.slice(colon);
fileName = fileName.replace(/\\/g, '/');
err.message = fileName + detail;
/**
* Runs the tests in the directory `test/${name}/` with all the supported versions of TS
*
* This function loads the gulp task from the `gulptask.js` file in the corresponding directory.
* Then, for each supported Typescript version, it executes it. The result is emitted in the
* `test/output/${name}/${tsVersion}` directories. It consists of a `dts` directory, `js` directory and
* `errors.txt`.
*
* @param name {string} Name of the test, corresponds to its directory name in `test/`
*/
async function runTest(name) {
const testDir = path.posix.join('test', name);
const outputDir = path.posix.join('test', 'output', name);

const newGulpTs = require('./release-2/main');
const testTask = require(`./${path.posix.join(testDir, 'gulptask.js')}`);

fs.mkdirSync(outputDir);
return Promise.all(libs.map(([tsVersion, tsLib]) => {
return new Promise((resolve, reject) => {
const errors = [];
let finishInfo;
const reporter = {
error (err) {
// File names embedded in error output contain OS-dependent path separators, normalize from Windows to Posix
if (path.sep === '\\') {
const colonIndex = err.message.indexOf(':');
if (colonIndex >= 0 && err.diagnostic && err.message.indexOf(path.sep) >= 0) {
const detail = err.message.slice(colonIndex);
const fileName = err.message.slice(0, colonIndex).replace(/\\/g, '/');
err.message= `${fileName}${detail}`;
}
})();

}
errors.push(err);
},
finish: function(info) {
finish(info) {
finishInfo = info;
}
};
fs.mkdirSync(output);
test(newTS, lib[1], output, reporter).on('finish', function() {
fs.writeFileSync(output + 'errors.txt', errors.join('\n') + '\n' + JSON.stringify(finishInfo, null, 4));
done++;
callback();
const curOutputDir = path.posix.join(outputDir, tsVersion);
fs.mkdirSync(curOutputDir);
testTask(newGulpTs, tsLib, `${curOutputDir}/`, reporter).on('finish', () => {
const result = [...errors, JSON.stringify(finishInfo, null, 4)].join('\n');
fs.writeFileSync(path.posix.join(curOutputDir, 'errors.txt'), result);
resolve();
});
})(i);
}
});
}));
}

gulp.task('test-run', ['clean-test', 'scripts'], function(cb) {
gulp.task('test-run', ['clean-test', 'scripts'], async function() {
fs.mkdirSync('test/output/');

var pending = tests.length * libs.length;
if (pending === 0) {
cb();
return;
for (const testName of tests) {
await runTest(testName);
}
});

var isFailed = false;
for (var i = 0; i < tests.length; i++) {
runTest(tests[i], function(failed) {
isFailed = isFailed || failed;
pending--;
if (pending === 0) {
if (isFailed) {
cb(new Error('Tests failed'));
} else {
cb();
}
}
// This allows catching possible counting errors.
else if (pending < 0) {
throw new Error('Callback called more than expected!');
}
});
}
})

gulp.task('test', ['test-run'], function(cb) {
var failed = false;
/**
* Executes all the test tasks and then compares their output against the expected output (defined in
* `test/baseline`).
*/
gulp.task('test', ['test-run'], function() {
let failed = false;
function onError(error) {
failed = true;
}
Expand Down
1 change: 0 additions & 1 deletion test/baselines/basic/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/basic/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/basic/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/bom/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/bom/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/bom/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/existingSourceMaps/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/existingSourceMaps/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/existingSourceMaps/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/externalResolve/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/externalResolve/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/externalResolve/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/out/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/out/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/out/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/sourceMaps/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/sourceMaps/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/sourceMaps/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/sourceMapsOutDir/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/sourceMapsOutDir/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/sourceMapsOutDir/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/tsconfigExtends/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/tsconfigExtends/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/tsconfigExtends/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/tsconfigOutFile/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/tsconfigOutFile/2.4/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
1 change: 0 additions & 1 deletion test/baselines/tsconfigOutFile/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"transpileErrors": 0,
"optionsErrors": 0,
Expand Down
4 changes: 2 additions & 2 deletions test/noEmit/gulptask.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var gulp = require('gulp');
const gulp = require('gulp');

module.exports = function(newTS, lib, output, reporter) {
return gulp.src('test/noEmit/**/*.ts')
.pipe(newTS({ noEmit: true, typescript: lib, outFile: 'foo.js' }, reporter))
.pipe(gulp.dest(output));
}
};