Skip to content

Commit

Permalink
Use Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Dec 3, 2016
1 parent a62c33c commit fee2426
Show file tree
Hide file tree
Showing 15 changed files with 1,034 additions and 203 deletions.
6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ yarn.lock
build/
test/
.travis.yml
.eslintrc

gulpfile.js
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ BUILD_CONFIGS.forEach(function (config) {
gulp.task('build', BUILD_CONFIGS);

gulp.task('test', ['build'], function () {
var mocha = require('gulp-mocha');
return gulp.src('build/*.js', { read: false }).pipe(mocha());
var jest = require('gulp-jest').default;
return gulp.src('build').pipe(jest());
});

gulp.task('default', ['lint', 'test']);
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"postcss-load-config": "^1.0.0"
},
"devDependencies": {
"chai": "^3.5.0",
"eslint": "^3.11.1",
"eslint-config-postcss": "^2.0.2",
"fs-extra": "^1.0.0",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-mocha": "^3.0.1",
"gulp-jest": "^0.6.0",
"json-loader": "^0.5.4",
"lint-staged": "^3.2.1",
"postcss-js": "^0.1.3",
Expand All @@ -42,6 +42,12 @@
"lint-staged": "lint-staged",
"test": "gulp"
},
"eslintConfig": {
"extends": "eslint-config-postcss/es5",
"env": {
"jest": true
}
},
"lint-staged": {
"*.js": "eslint"
},
Expand Down
4 changes: 1 addition & 3 deletions test/test-custom-parser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
var expect = require('chai').expect;

describe('custom parser', function () {

it('processes sugarss', function () {
var css = require('!raw-loader!../!' +
'./cases/sugar.css');
expect(css).to.eql('a\n color: rgba(255, 0, 0, 0.1)\n');
expect(css).toEqual('a\n color: rgba(255, 0, 0, 0.1)\n');
});

});
20 changes: 9 additions & 11 deletions test/test-default.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,58 @@
var expect = require('chai').expect;

describe('default', function () {

it('processes CSS with default plugins', function () {
var css = require('!raw-loader!../!./cases/style.css');
expect(css).to.eql('a { color: blue }\n');
expect(css).toEqual('a { color: blue }\n');
});

it('overrides default config by subdir config', function () {
var css = require('!raw-loader!../!./cases/config/style.css');
expect(css).to.eql('a { color: black }\n');
expect(css).toEqual('a { color: black }\n');
});

it('send webpack instance to config', function () {
var css = require('!raw-loader!../!./cases/env/style.css');
expect(css).to.eql('a::before { content: "style.css" }\n');
expect(css).toEqual('a::before { content: "style.css" }\n');
});

it('processes CSS in safe mode', function () {
var css = require('!raw-loader' +
'!../?parser=postcss-safe-parser' +
'!./cases/broken.css');
expect(css).to.eql('a { color:\n}');
expect(css).toEqual('a { color:\n}');
});

it('lets other plugins alter the used plugins', function () {
var css = require('!raw-loader!../?rewrite=true' +
'!./cases/style.css');
expect(css).to.eql('a { color: black }\n');
expect(css).toEqual('a { color: black }\n');
});

it('processes CSS-in-JS', function () {
var css = require('!raw-loader' +
'!../?parser=postcss-js' +
'!./cases/style.js');
expect(css).to.eql('a {\n color: blue\n}');
expect(css).toEqual('a {\n color: blue\n}');
});

it('processes CSS with exec', function () {
var css = require('!raw-loader' +
'!../?exec' +
'!./cases/exec.js');
expect(css).to.eql('a {\n color: green\n}');
expect(css).toEqual('a {\n color: green\n}');
});

it('inlines map', function () {
var css = require('!raw-loader!../?sourceMap=inline' +
'!./cases/style.css');
expect(css).to.include('/*# sourceMappingURL=');
expect(css).toContain('/*# sourceMappingURL=');
});

it('allows to change config path', function () {
var css = require('!raw-loader' +
'!../?config=test/cases/config/postcss.config.js' +
'!./cases/style.css');
expect(css).to.eql('a { color: black }\n');
expect(css).toEqual('a { color: black }\n');
});

});
4 changes: 1 addition & 3 deletions test/test-explicit-plugins.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
var expect = require('chai').expect;

describe('explicit plugins', function () {

it('processes CSS with custom plugins', function () {
var css = require('!raw-loader!../!' +
'./cases/style.css');
expect(css).to.eql('a { color: rgba(255, 0, 0, 0.1) }\n');
expect(css).toEqual('a { color: rgba(255, 0, 0, 0.1) }\n');
});

});
4 changes: 1 addition & 3 deletions test/test-incorrect-using-packs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var expect = require('chai').expect;

describe('incorrect using packs', function () {

it('fails to load specific pack', function () {
Expand All @@ -10,7 +8,7 @@ describe('incorrect using packs', function () {
} catch (err) {
error = err;
}
expect(error.message).to.match(/find module/);
expect(error.message).toMatch(/find module/);
});

});
6 changes: 2 additions & 4 deletions test/test-with-packs.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
var expect = require('chai').expect;

describe('with packs', function () {

it('processes CSS with default plugins', function () {
var css = require('!raw-loader!../!' +
'./cases/style.css');
expect(css).to.eql('a { color: rgba(255, 0, 0, 0.1) }\n');
expect(css).toEqual('a { color: rgba(255, 0, 0, 0.1) }\n');
});

it('processes CSS with custom plugins', function () {
var css = require('!raw-loader!../?pack=blues!' +
'./cases/style.css');
expect(css).to.eql('a { color: blue }\n');
expect(css).toEqual('a { color: blue }\n');
});

});
1 change: 1 addition & 0 deletions test/webpack-custom-parser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
context: __dirname,
entry: './test-custom-parser.js',
output: {
filename: 'test-custom-parser.test.js',
path: path.join(__dirname, '..', 'build')
},
postcss: function () {
Expand Down
1 change: 1 addition & 0 deletions test/webpack-default.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
context: __dirname,
entry: './test-default.js',
output: {
filename: 'test-default.test.js',
path: path.join(__dirname, '..', 'build')
},
plugins: [
Expand Down
1 change: 1 addition & 0 deletions test/webpack-explicit-plugins.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
context: __dirname,
entry: './test-explicit-plugins.js',
output: {
filename: 'test-explicit-plugins.test.js',
path: path.join(__dirname, '..', 'build')
},
postcss: function () {
Expand Down
1 change: 1 addition & 0 deletions test/webpack-incorrect-using-packs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
context: __dirname,
entry: './test-incorrect-using-packs.js',
output: {
filename: 'test-incorrect-using-packs.test.js',
path: path.join(__dirname, '..', 'build')
},
plugins: [
Expand Down
1 change: 1 addition & 0 deletions test/webpack-with-packs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
context: __dirname,
entry: './test-with-packs.js',
output: {
filename: 'test-with-packs.test.js',
path: path.join(__dirname, '..', 'build')
},
postcss: function () {
Expand Down
Loading

0 comments on commit fee2426

Please sign in to comment.