diff --git a/packages/react-server-gulp-module-tagger/gulpfile.js b/packages/react-server-gulp-module-tagger/gulpfile.js index ecc0412ff..a763fdca0 100644 --- a/packages/react-server-gulp-module-tagger/gulpfile.js +++ b/packages/react-server-gulp-module-tagger/gulpfile.js @@ -1,8 +1,13 @@ const path = require('path'); const gulp = require('gulp'); +const ava = require('gulp-ava'); const nsp = require('gulp-nsp'); const eslint = require('gulp-eslint'); +gulp.task('ava', () => gulp.src('test/test.js') + .pipe(ava()) +); + gulp.task('eslint', [], () => gulp.src("index.js") .pipe(eslint()) .pipe(eslint.format()) @@ -11,4 +16,4 @@ gulp.task('eslint', [], () => gulp.src("index.js") gulp.task('nsp', (cb) => nsp({package: path.resolve('package.json')}, cb)); -gulp.task('test', ['nsp', 'eslint']); +gulp.task('test', ['ava', 'nsp', 'eslint']); diff --git a/packages/react-server-gulp-module-tagger/package.json b/packages/react-server-gulp-module-tagger/package.json index c0048be78..8624d4195 100644 --- a/packages/react-server-gulp-module-tagger/package.json +++ b/packages/react-server-gulp-module-tagger/package.json @@ -18,6 +18,8 @@ "gulp-replace": "0.5.2" }, "devDependencies": { + "ava": "^0.15.2", + "gulp-ava": "^0.12.0", "rimraf": "^2.5.2" } } diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/example/actual.js b/packages/react-server-gulp-module-tagger/test/fixtures/example/actual.js new file mode 100644 index 000000000..397c15fe9 --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/example/actual.js @@ -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" })); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/example/build/actual.js b/packages/react-server-gulp-module-tagger/test/fixtures/example/build/actual.js new file mode 100644 index 000000000..ca23d1f03 --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/example/build/actual.js @@ -0,0 +1,3 @@ +var logger = require('react-server').logging.getLogger({"name":"react-server-gulp-module-tagger.test.fixtures.example.actual","color":{"server":217,"client":"rgb(212,127,127)"}}); +var fooLogger = logging.getLogger({"label":"foo","name":"react-server-gulp-module-tagger.test.fixtures.example.actual.foo","color":{"server":217,"client":"rgb(212,127,127)"}}); +var barLogger = logging.getLogger({"label":"bar","name":"react-server-gulp-module-tagger.test.fixtures.example.actual.bar","color":{"server":217,"client":"rgb(212,127,127)"}}); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/example/expected.js b/packages/react-server-gulp-module-tagger/test/fixtures/example/expected.js new file mode 100644 index 000000000..ca23d1f03 --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/example/expected.js @@ -0,0 +1,3 @@ +var logger = require('react-server').logging.getLogger({"name":"react-server-gulp-module-tagger.test.fixtures.example.actual","color":{"server":217,"client":"rgb(212,127,127)"}}); +var fooLogger = logging.getLogger({"label":"foo","name":"react-server-gulp-module-tagger.test.fixtures.example.actual.foo","color":{"server":217,"client":"rgb(212,127,127)"}}); +var barLogger = logging.getLogger({"label":"bar","name":"react-server-gulp-module-tagger.test.fixtures.example.actual.bar","color":{"server":217,"client":"rgb(212,127,127)"}}); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/example/gulpfile.js b/packages/react-server-gulp-module-tagger/test/fixtures/example/gulpfile.js new file mode 100644 index 000000000..88048261e --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/example/gulpfile.js @@ -0,0 +1,8 @@ +const gulp = require('gulp'); +const tagger = require('../../..'); + +gulp.task('default', () => { + gulp.src('actual.js') + .pipe(tagger()) + .pipe(gulp.dest('build')); +}); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/actual.js b/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/actual.js new file mode 100644 index 000000000..4d86c7533 --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/actual.js @@ -0,0 +1,2 @@ +__CHANNEL__ +__CACHE__ diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/build/actual.js b/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/build/actual.js new file mode 100644 index 000000000..d6423d80e --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/build/actual.js @@ -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)"}} diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/expected.js b/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/expected.js new file mode 100644 index 000000000..d6423d80e --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/expected.js @@ -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)"}} diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/gulpfile.js b/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/gulpfile.js new file mode 100644 index 000000000..88048261e --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/reserved-future-tokens/gulpfile.js @@ -0,0 +1,8 @@ +const gulp = require('gulp'); +const tagger = require('../../..'); + +gulp.task('default', () => { + gulp.src('actual.js') + .pipe(tagger()) + .pipe(gulp.dest('build')); +}); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/trim/actual.js b/packages/react-server-gulp-module-tagger/test/fixtures/trim/actual.js new file mode 100644 index 000000000..397c15fe9 --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/trim/actual.js @@ -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" })); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/trim/build/actual.js b/packages/react-server-gulp-module-tagger/test/fixtures/trim/build/actual.js new file mode 100644 index 000000000..fb0047b2a --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/trim/build/actual.js @@ -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)"}}); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/trim/expected.js b/packages/react-server-gulp-module-tagger/test/fixtures/trim/expected.js new file mode 100644 index 000000000..fb0047b2a --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/trim/expected.js @@ -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)"}}); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/trim/gulpfile.js b/packages/react-server-gulp-module-tagger/test/fixtures/trim/gulpfile.js new file mode 100644 index 000000000..9339d0d6e --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/trim/gulpfile.js @@ -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')); +}); diff --git a/packages/react-server-gulp-module-tagger/test/test.js b/packages/react-server-gulp-module-tagger/test/test.js new file mode 100644 index 000000000..bd3fed3fb --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/test.js @@ -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); + } + }); + }); +}