Skip to content

Commit

Permalink
test(*): move config from package to test folder, fixed #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Dec 12, 2016
1 parent 31de91a commit 502223d
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 31 deletions.
19 changes: 0 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@
"husky": "^0.11.9",
"nyc": "^10.0.0",
"np": "^2.11.0",
"postcss-cli": "^2.5.2",
"posthtml": "^0.9.0",
"posthtml-bem": "^0.2.2",
"posthtml-css-modules": "^0.1.0",
"posthtml-each": "^1.0.1",
"posthtml-include": "^1.1.0",
"posthtml-modules": "^0.4.0",
"posthtml-standard-config": "0.0.5",
"posthtml-style-to-file": "^0.1.1",
"updtr": "^0.2.1"
},
"ava": {
Expand Down Expand Up @@ -134,15 +125,5 @@
"off"
]
}
},
"posthtml": {
"bem": {
"elemPrefix": "__",
"modPrefix": "--",
"modDlmtr": "-"
},
"styleToFile": {
"path": "test/dist/styleToFile.css"
}
}
}
2 changes: 1 addition & 1 deletion test/fixtures/posthtml.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"encoding": "utf-8"
},
"styleToFile": {
"path": "test/dist/style.css"
"path": "dist/style.css"
}
}
102 changes: 102 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"name": "test-post-load-plugins",
"dependencies": {
"chalk": "^1.1.3",
"indent-string": "^3.0.0",
"log-symbols": "^1.0.2",
"post-config": "0.0.3",
"post-sequence": "^0.1.9",
"text-table": "^0.2.0"
},
"devDependencies": {
"ava": "*",
"ava-codemods": "^0.3.0",
"babel-cli": "^6.11.4",
"babel-eslint": "^7.1.1",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-preset-babili": "0.0.9",
"babel-preset-es2015": "^6.14.0",
"babel-register": "^6.16.0",
"clinton": "^0.8.0",
"conventional-changelog-cli": "^1.2.0",
"conventional-changelog-lint": "^1.0.0",
"coveralls": "^2.11.14",
"eslint": "^3.8.0",
"eslint-config-xo": "^0.17.0",
"eslint-formatter-pretty": "^1.1.0",
"eslint-plugin-ava": "^4.0.0",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-markdown": "^1.0.0-beta.2",
"eslint-plugin-require-path-exists": "^1.1.5",
"eslint-plugin-xo": "^1.0.0",
"husky": "^0.11.9",
"nyc": "^10.0.0",
"np": "^2.11.0",
"postcss-cli": "^2.5.2",
"posthtml": "^0.9.0",
"posthtml-bem": "^0.2.2",
"posthtml-css-modules": "^0.1.0",
"posthtml-each": "^1.0.1",
"posthtml-include": "^1.1.0",
"posthtml-modules": "^0.4.0",
"posthtml-standard-config": "0.0.5",
"posthtml-style-to-file": "^0.1.1",
"updtr": "^0.2.1"
},
"ava": {
"require": [
"babel-register"
]
},
"babel": {
"presets": [
"es2015",
"babili"
],
"plugins": [
"add-module-exports"
]
},
"eslintConfig": {
"format": "node_modules/eslint-formatter-pretty",
"parser": "babel-eslint",
"plugins": [
"ava",
"xo",
"babel",
"require-path-exists",
"markdown"
],
"extends": [
"xo",
"plugin:xo/recommended",
"plugin:ava/recommended"
]
},
"clinton": {
"ignores": [
"test/**",
"tmp/**",
"lib/**",
"*.{html,jpg}"
],
"rules": {
"pkg-main": [
"off"
],
"xo": [
"off"
]
}
},
"posthtml": {
"bem": {
"elemPrefix": "__",
"modPrefix": "--",
"modDlmtr": "-"
},
"styleToFile": {
"path": "dist/styleToFile.css"
}
}
}
25 changes: 14 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const readFile = require('fs').readFile;
const posthtml = require('posthtml');
const test = require('ava');
const plugin = require('../src/index.js');
import path from 'path';
import {readFile} from 'fs';
import posthtml from 'posthtml';
import test from 'ava';
import postLoadPlugins from '../src/index.js';

process.chdir(path.resolve(process.cwd() + '/test'));

const read = path => new Promise((resolve, reject) => {
readFile(path, 'utf8', (err, data) => {
Expand All @@ -13,26 +16,26 @@ const read = path => new Promise((resolve, reject) => {
});

test('Plugin return array', t => {
t.true(Array.isArray(plugin()));
t.true(Array.isArray(postLoadPlugins()));
});

test('Plugin reads custom json config from posthtml.json', async t => {
t.is(
(await read('test/expected/output-config-pkg.html')),
(await posthtml(plugin('test/fixtures/posthtml.json')).process(await read('test/fixtures/input.html'))).html
(await read('expected/output-config-pkg.html')),
(await posthtml(postLoadPlugins('fixtures/posthtml.json')).process(await read('fixtures/input.html'))).html
);
});

test('test witch posthtml-css-modules', async t => {
t.is(
(await read('test/expected/output-modules.html')),
(await posthtml(plugin('test/fixtures/modules.json', {'posthtml-css-modules': 'test/dist/css-modules.json', 'posthtml-each': {}})).process(await read('test/fixtures/input-modules.html'))).html
(await read('expected/output-modules.html')),
(await posthtml(postLoadPlugins('fixtures/modules.json', {'posthtml-css-modules': 'dist/css-modules.json', 'posthtml-each': {}})).process(await read('fixtures/input-modules.html'))).html
);
});

test('should throw not install plugin posthtml-css', async t => {
t.is(
(await read('test/expected/output-config-pkg.html')),
(await posthtml(plugin('test/fixtures/posthtml.json', {css: {}, postcss: {}})).process(await read('test/fixtures/input.html'))).html
(await read('expected/output-config-pkg.html')),
(await posthtml(postLoadPlugins('fixtures/posthtml.json', {css: {}, postcss: {}})).process(await read('fixtures/input.html'))).html
);
});

0 comments on commit 502223d

Please sign in to comment.