Permalink
Browse files

use ava to test

  • Loading branch information...
egoist committed May 29, 2016
1 parent 4af45f3 commit 9698d66ca1f04a2308c94fe74d94d184f2891b96
Showing with 139 additions and 70 deletions.
  1. +9 −0 .babelrc
  2. +1 −1 .gitignore
  3. +3 −1 README.md
  4. +19 −9 package.json
  5. +3 −1 rollup.config.js
  6. +12 −10 src/index.js
  7. +20 −0 test.js
  8. +63 −29 tests/build.js
  9. +4 −0 tests/fixture_parser.js
  10. +2 −0 tests/helpers/set-browser-env.js
  11. +3 −0 tests/sugarss.sss
  12. +0 −19 tests/test.js
@@ -0,0 +1,9 @@
{
"presets": [
"es2015",
"stage-1"
],
"plugins": [
"transform-runtime"
]
}
@@ -1,5 +1,5 @@
/index.js
/tests/output.js*
/tests/output*.js*
# Logs
logs
@@ -27,7 +27,9 @@ rollup({
plugins: [
// cssnext(),
// yourPostcssPlugin()
]
],
extensions: ['.css', '.sss'] // default value
// parser: sugarss
})
]
}).then(...)
@@ -4,8 +4,12 @@
"description": "Seamless integration between Rollup and PostCSS",
"main": "index.js",
"jsnext:main": "./src/index.js",
"files": [
"index.js",
"src"
],
"scripts": {
"test": "npm run build && mocha --compilers js:babel-core/register tests/test.js --recursive",
"test": "ava test.js",
"build": "rollup -c -o index.js"
},
"repository": {
@@ -23,20 +27,26 @@
},
"homepage": "https://github.com/egoist/rollup-plugin-postcss#readme",
"devDependencies": {
"ava": "^0.7.0",
"babel-core": "^5.8.32",
"chai": "^3.4.1",
"jsdom": "^7.2.0",
"mocha": "^2.3.4",
"mocha-jsdom": "^1.0.0",
"ava": "^0.15.1",
"babel-preset-es2015-rollup": "^1.1.1",
"babel-preset-stage-1": "^6.5.0",
"babel-register": "^6.9.0",
"jsdom": "^9.2.1",
"postcss-nested": "^1.0.0",
"require-from-string": "^1.1.0",
"rollup": "^0.21.2",
"rollup-plugin-babel": "^1.0.0"
"rollup": "^0.26.3",
"rollup-plugin-babel": "^2.4.0",
"sugarss": "^0.1.3"
},
"dependencies": {
"postcss": "^5.0.12",
"rollup-pluginutils": "^1.2.0",
"style-inject": "0.0.11"
},
"ava": {
"require": [
"./tests/helpers/set-browser-env.js",
"babel-register"
]
}
}
@@ -6,7 +6,9 @@ export default {
entry: 'src/index.js',
plugins: [
babel({
exclude: 'node_modules/**'
exclude: 'node_modules/**',
presets: ['es2015-rollup'],
babelrc: false
})
],
external,
@@ -3,28 +3,30 @@ import postcss from 'postcss';
import styleInject from 'style-inject';
import path from 'path';
function pathJoin (file) {
function cwd(file) {
return path.join(process.cwd(), file);
}
export default function (options = {}) {
const filter = createFilter( options.include, options.exclude );
const filter = createFilter(options.include, options.exclude);
const injectFnName = '__$styleInject'
const extensions = options.extensions || ['.css', '.sss']
return {
intro () {
intro() {
return styleInject.toString().replace(/styleInject/, injectFnName);
},
transform (code, id) {
if (!filter( id ) || id.slice( -4 ) !== '.css') {
return null;
}
transform(code, id) {
if (!filter(id)) return null
if (extensions.indexOf(path.extname(id)) === -1) return null
const opts = {
from: options.from ? pathJoin(options.from) : id,
to: options.to ? pathJoin(options.to) : id,
from: options.from ? cwd(options.from) : id,
to: options.to ? cwd(options.to) : id,
map: {
inline: false,
annotation: false
}
},
parser: options.parser
};
return postcss(options.plugins || [])
.process(code, opts)
20 test.js
@@ -0,0 +1,20 @@
import test from 'ava';
import requireFromString from 'require-from-string';
import {
buildDefault,
buildWithParser
} from './tests/build';
test('test postcss', async t => {
const data = await buildDefault().catch(err => console.log(err.stack));
requireFromString(data);
const styles = window.getComputedStyle(document.body);
t.is(styles.margin, '0px');
});
test('use sugarss as parser', async t => {
const data = await buildWithParser().catch(err => console.log(err.stack));
requireFromString(data);
const styles = window.getComputedStyle(document.body);
t.is(styles.fontSize, '20px');
});
@@ -1,36 +1,70 @@
import fs from 'fs';
import { rollup } from 'rollup';
import babel from 'rollup-plugin-babel';
import postcss from '../src/index';
import fs from 'fs';
import sugarss from 'sugarss';
export function buildDefault() {
return rollup({
plugins: [
postcss({
include: '**/*.css',
sourceMap: true,
plugins: [
require('postcss-nested')
]
}),
babel({
babelrc: false,
presets: ['es2015-rollup'],
include: '**/*.js',
sourceMap: true
}),
],
entry: __dirname +'/fixture.js'
}).then(bundle => {
const result = bundle.generate({
format: 'umd',
sourceMap: true,
});
bundle.write({
dest: './tests/output.js',
format: 'umd',
sourceMap: true
});
return result.code;
})
};
export default function (plugins = []) {
return new Promise(async (resolve, reject) => {
await rollup({
plugins: [
postcss({
include: '**/*.css',
sourceMap: true,
plugins: [
require('postcss-nested')
]
}),
babel({
exclude: '**/*.css',
sourceMap: true
}),
],
entry: __dirname +'/fixture.js'
}).then(bundle => {
const result = bundle.generate({
format: 'umd',
export function buildWithParser() {
return rollup({
plugins: [
postcss({
include: '**/*.sss',
sourceMap: true,
});
bundle.write({
dest: './tests/output.js',
format: 'umd',
parser: sugarss,
plugins: [
require('postcss-nested')
]
}),
babel({
babelrc: false,
presets: ['es2015-rollup'],
include: '**/*.js',
sourceMap: true
});
resolve(result.code);
}).catch(err => reject(err));
});
}),
],
entry: __dirname +'/fixture_parser.js'
}).then(bundle => {
const result = bundle.generate({
format: 'umd',
sourceMap: true,
});
bundle.write({
dest: './tests/output_parser.js',
format: 'umd',
sourceMap: true
});
return result.code;
})
};
@@ -0,0 +1,4 @@
import './sugarss.sss';
const a = function () {
};
a();
@@ -0,0 +1,2 @@
global.document = require('jsdom').jsdom('<body></body>');
global.window = document.defaultView;
@@ -0,0 +1,3 @@
html
body
font-size: 20px

This file was deleted.

Oops, something went wrong.

0 comments on commit 9698d66

Please sign in to comment.