Skip to content

Commit

Permalink
Cleanup tests (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored May 11, 2019
1 parent dc23eb5 commit 0dee7f7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "gulp",
"parserOptions": {
"ecmaVersion": 2015
},
"extends": "gulp"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"scripts": {
"pretest": "npm run lint",
"test": "mocha test",
"test": "mocha --async-only",
"lint": "eslint index.js \"test/**/*.js\""
},
"license": "MIT",
Expand Down
11 changes: 2 additions & 9 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{
"globals": {
"describe": true,
"it": true
},
"extends": "gulp/test",
"parserOptions": {
"ecmaVersion": 2015
},
"rules": {
"max-len": "off"
},
"extends": "gulp"
}
}
19 changes: 8 additions & 11 deletions test/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ const { getFixture } = require('./get-fixture');

describe('error', function() {
it('should emit errors of pug correctly', function(done) {
pipe(
[from.obj([getFixture('pug-error.pug')]), task(), concat()],
(err) => {
try {
expect(err).toBeInstanceOf(PluginError);
done();
} catch (err) {
done(err);
}
}
);
pipe([
from.obj([getFixture('pug-error.pug')]),
task(),
concat(),
], (err) => {
expect(err).toBeInstanceOf(PluginError);
done();
});
});
});
19 changes: 8 additions & 11 deletions test/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ const file = new Vinyl({

describe('stream', function() {
it('should error if contents is a stream', function(done) {
pipe(
[from.obj([file]), task(), concat()],
(err) => {
try {
expect(err).toBeInstanceOf(PluginError);
done();
} catch (err) {
done(err);
}
}
);
pipe([
from.obj([file]),
task(),
concat(),
], (err) => {
expect(err).toBeInstanceOf(PluginError);
done();
});
});
});
31 changes: 11 additions & 20 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ function setData() {
});
}

function expectStream(options) {
function assertStream(options) {
options = options || {};
const ext = options.client ? '.js' : '.html';
const compiler = options.client ? pug.compileClient : pug.compile;

function assert(file, _enc, cb) {
function assert(file) {
options.filename = file.path.replace(new RegExp(ext + '$'), '.pug');
const compiled = compiler(fs.readFileSync(options.filename), options);
const data = Object.assign({}, options.data, options.locals, file.data);
Expand All @@ -38,19 +38,17 @@ function expectStream(options) {
} else {
expect(path.extname(file.relative)).toStrictEqual('');
}
cb(null, file);
}

return through.obj(assert);
return concat((files) => files.forEach(assert));
}

describe('test', function() {
it('should compile my pug files into HTML', function(done) {
pipe([
from.obj([getFixture('helloworld.pug')]),
task(),
expectStream(),
concat(),
assertStream(),
], done);
});

Expand All @@ -64,8 +62,7 @@ describe('test', function() {
pipe([
from.obj([getFixture('helloworld.pug')]),
task(options),
expectStream(options),
concat(),
assertStream(options),
], done);
});

Expand All @@ -79,8 +76,7 @@ describe('test', function() {
pipe([
from.obj([getFixture('helloworld.pug')]),
task(options),
expectStream(options),
concat(),
assertStream(options),
], done);
});

Expand All @@ -89,8 +85,7 @@ describe('test', function() {
from.obj([getFixture('helloworld.pug')]),
setData(),
task(),
expectStream({ data: { title: 'Greetings' } }),
concat(),
assertStream({ data: { title: 'Greetings' } }),
], done);
});

Expand All @@ -99,8 +94,7 @@ describe('test', function() {
from.obj([getFixture('helloworld.pug')]),
setData(),
task({ data: { foo: 'bar' } }),
expectStream({ data: { title: 'Greetings', foo: 'bar' } }),
concat(),
assertStream({ data: { title: 'Greetings', foo: 'bar' } }),
], done);
});

Expand All @@ -109,8 +103,7 @@ describe('test', function() {
from.obj([getFixture('helloworld.pug')]),
setData(),
task({ data: { title: 'Yellow Curled' } }),
expectStream({ data: { title: 'Greetings' } }),
concat(),
assertStream({ data: { title: 'Greetings' } }),
], done);
});

Expand All @@ -129,8 +122,7 @@ describe('test', function() {
cb(null, file);
}),
task(),
expectStream(),
concat(),
assertStream(),
], done);
});

Expand All @@ -140,8 +132,7 @@ describe('test', function() {
pipe([
from.obj([getFixture('helloworld.pug')]),
task(options),
expectStream(options),
concat(),
assertStream(options),
], done);
});

Expand Down

0 comments on commit 0dee7f7

Please sign in to comment.