Skip to content

Commit

Permalink
Add gulp module tagger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-wade committed Jun 21, 2016
1 parent f32f8a8 commit 455c9da
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/react-server-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "target/index.js",
"scripts": {
"prepublish": "gulp",
"test": "gulp test && nsp check",
"test": "gulp test",
"clean": "rimraf target npm-debug.log*"
},
"author": "Sasha Aickin",
Expand Down
23 changes: 16 additions & 7 deletions packages/react-server-gulp-module-tagger/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
const path = require('path');
const gulp = require('gulp');
const nsp = require('gulp-nsp');
const eslint = require('gulp-eslint');
const path = require('path');
const gulp = require('gulp');
const ava = require('gulp-ava');
const nsp = require('gulp-nsp');
const eslint = require('gulp-eslint');
const plumber = require('gulp-plumber');
const gutil = require('gulp-util');

gulp.task('ava', () => gulp.src('test/test.js')
.pipe(plumber())
.pipe(ava())
.on('error', gutil.log)
);

gulp.task('eslint', [], () => gulp.src("index.js")
.pipe(plumber())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.on('error', gutil.log)
);

gulp.task('nsp', (cb) => nsp({package: path.resolve('package.json')}, cb));

gulp.task('test', ['nsp', 'eslint']);
gulp.task('test', ['ava', 'eslint']);
5 changes: 4 additions & 1 deletion packages/react-server-gulp-module-tagger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A gulp plugin to replace tags with module information",
"main": "index.js",
"scripts": {
"test": "gulp test",
"test": "gulp test && nsp check",
"clean": "rimraf target npm-debug.log*"
},
"repository": "redfin/react-server",
Expand All @@ -18,6 +18,9 @@
"gulp-replace": "0.5.2"
},
"devDependencies": {
"ava": "^0.15.2",
"gulp-ava": "^0.12.0",
"gulp-plumber": "^1.1.0",
"rimraf": "^2.5.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var logger = require('react-server').logging.getLogger(__LOGGER__);
var fooLogger = logging.getLogger(__LOGGER__({ label: "foo" }));
var barLogger = logging.getLogger(__LOGGER__({ label: "bar" }));

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const gulp = require('gulp');
const tagger = require('../../..');

gulp.task('default', () => {
gulp.src('actual.js')
.pipe(tagger())
.pipe(gulp.dest('build'));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__CHANNEL__
__CACHE__
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"name":"react-server-gulp-module-tagger.test.fixtures.reserved-future-tokens.actual","color":{"server":205,"client":"rgb(212,42,127)"}}
{"name":"react-server-gulp-module-tagger.test.fixtures.reserved-future-tokens.actual","color":{"server":205,"client":"rgb(212,42,127)"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"name":"react-server-gulp-module-tagger.test.fixtures.reserved-future-tokens.actual","color":{"server":205,"client":"rgb(212,42,127)"}}
{"name":"react-server-gulp-module-tagger.test.fixtures.reserved-future-tokens.actual","color":{"server":205,"client":"rgb(212,42,127)"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const gulp = require('gulp');
const tagger = require('../../..');

gulp.task('default', () => {
gulp.src('actual.js')
.pipe(tagger())
.pipe(gulp.dest('build'));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var logger = require('react-server').logging.getLogger(__LOGGER__);
var fooLogger = logging.getLogger(__LOGGER__({ label: "foo" }));
var barLogger = logging.getLogger(__LOGGER__({ label: "bar" }));
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var logger = require('react-server').logging.getLogger({"name":"fixtures.trim.actual","color":{"server":147,"client":"rgb(127,127,212)"}});
var fooLogger = logging.getLogger({"label":"foo","name":"fixtures.trim.actual.foo","color":{"server":147,"client":"rgb(127,127,212)"}});
var barLogger = logging.getLogger({"label":"bar","name":"fixtures.trim.actual.bar","color":{"server":147,"client":"rgb(127,127,212)"}});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var logger = require('react-server').logging.getLogger({"name":"fixtures.trim.actual","color":{"server":147,"client":"rgb(127,127,212)"}});
var fooLogger = logging.getLogger({"label":"foo","name":"fixtures.trim.actual.foo","color":{"server":147,"client":"rgb(127,127,212)"}});
var barLogger = logging.getLogger({"label":"bar","name":"fixtures.trim.actual.bar","color":{"server":147,"client":"rgb(127,127,212)"}});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const gulp = require('gulp');
const tagger = require('../../..');

gulp.task('default', () => {
gulp.src('actual.js')
.pipe(tagger({ trim: 'react-server-gulp-module-tagger.test.' }))
.pipe(gulp.dest('build'));
});
53 changes: 53 additions & 0 deletions packages/react-server-gulp-module-tagger/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import test from 'ava';
import fs from 'fs';
import cp from 'child_process';
import path from 'path';

getTestCases().then((testCases) => {
testCases.forEach((dir) => {
test(`testing fixture in ${dir}`, async t => {
await runGulp(dir);
const expected = await readFile(path.join('fixtures', dir, 'expected.js'));
const actual = await readFile(path.join('fixtures', dir, 'build', 'actual.js'));
t.is(actual.toString(), expected.toString());
});
});
});

function getTestCases() {
return new Promise((resolve, reject) => {
fs.readdir('fixtures', (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
})
})
}

function readFile(filename) {
return new Promise((resolve, reject) => {
fs.readFile(filename, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

function runGulp(dir) {
return new Promise((resolve, reject) => {
dir = path.join(__dirname, 'fixtures', dir);
cp.exec('gulp', { cwd: dir }, (err, stdout, stderr) => {
if (err) {
console.error(stderr);
reject(err);
} else {
resolve(stdout);
}
});
});
}

0 comments on commit 455c9da

Please sign in to comment.