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

Add gulp module tagger tests #294

Merged
merged 2 commits into from
Jun 24, 2016
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ addons:

before_script:
- npm run bootstrap

after_failure:
- npm run debug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"bootstrap": "npm i; lerna bootstrap",
"test": "lerna run test",
"clean": "rimraf lerna-debug.log && lerna run clean",
"nuke": "lerna clean && rm -r node_modules"
"nuke": "lerna clean && rm -r node_modules",
"debug": "cat lerna-debug.log && for d in packages/*/npm-debug.log*; do echo $d; cat $d; done"
},
"devDependencies": {
"babel-plugin-react-require": "^2.1.0",
Expand Down
14 changes: 0 additions & 14 deletions packages/react-server-gulp-module-tagger/gulpfile.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/react-server-gulp-module-tagger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var getColor = (function(){
return (hash%len+len)%len;
}

return function(fn){
return colors[hash(fn)];
return function(fn, opts){
return colors[hash(opts.name)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fn is no longer used?

}
})();
6 changes: 5 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": "ava test/test.js && eslint index.js && nsp check",
"clean": "rimraf target npm-debug.log*"
},
"repository": "redfin/react-server",
Expand All @@ -15,9 +15,13 @@
],
"dependencies": {
"gulp-foreach": "0.1.0",
"gulp-plumber": "^1.1.0",
"gulp-replace": "0.5.2"
},
"devDependencies": {
"ava": "^0.15.2",
"del": "^2.2.1",
"nsp": "^2.4.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.

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":215,"client":"rgb(212,127,42)"}}
{"name":"react-server-gulp-module-tagger.test.fixtures.reserved-future-tokens.actual","color":{"server":215,"client":"rgb(212,127,42)"}}
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":227,"client":"rgb(212,212,42)"}});
var fooLogger = logging.getLogger({"label":"foo","name":"fixtures.trim.actual.foo","color":{"server":85,"client":"rgb(42,212,127)"}});
var barLogger = logging.getLogger({"label":"bar","name":"fixtures.trim.actual.bar","color":{"server":73,"client":"rgb(42,127,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({ trim: 'react-server-gulp-module-tagger.test.' }))
.pipe(gulp.dest('build'));
});
72 changes: 72 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,72 @@
import test from 'ava';
import fs from 'fs';
import cp from 'child_process';
import path from 'path';
import del from 'del';

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());
});
});
});

test('module can be required', t => {
try {
require('..');
t.pass();
} catch (e) {
t.fail();
}
});

test.after.always('cleanup', async t => {
const promises = [];
const fixtures = await getTestCases();
fixtures.forEach(fixture => {
promises.push(del(path.join('fixtures', fixture, 'build')));
})
await Promise.all(promises);
});

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);
}
});
});
}