mirror of
https://github.com/developit/microbundle.git
synced 2025-12-08 17:35:50 +00:00
Add a proper test harness (via Jest)
This commit is contained in:
parent
f25d9684e9
commit
5baf00a35b
14
package.json
14
package.json
@ -12,15 +12,18 @@
|
||||
"prepare": "npm run -s build",
|
||||
"prepare:babel": "babel --presets env src/*.js -d dist && npm t",
|
||||
"lint": "eslint src",
|
||||
"test:build": "node dist/cli.js --no-compress --cwd test/demo",
|
||||
"test:build:ts": "node dist/cli.js --no-compress --cwd test/ts-demo --entry=src/index.ts",
|
||||
"test": "npm run -s lint && npm run -s build && npm run -s test:build && npm run -s test:build:ts",
|
||||
"test": "npm run -s lint && npm run -s build && jest",
|
||||
"release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
|
||||
},
|
||||
"repository": "developit/microbundle",
|
||||
"eslintConfig": {
|
||||
"extends": "eslint-config-developit"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
"env"
|
||||
]
|
||||
},
|
||||
"keywords": [
|
||||
"bundle",
|
||||
"rollup",
|
||||
@ -66,6 +69,9 @@
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"eslint": "^4.15.0",
|
||||
"eslint-config-developit": "^1.1.1"
|
||||
"eslint-config-developit": "^1.1.1",
|
||||
"fs-extra": "^5.0.0",
|
||||
"jest": "^22.1.4",
|
||||
"strip-ansi": "^4.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
31
test/demo.test.js
Normal file
31
test/demo.test.js
Normal file
@ -0,0 +1,31 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import { strip } from './lib/util';
|
||||
import microbundle from '../src/index';
|
||||
|
||||
describe('demo', () => {
|
||||
it('should produce build files', async () => {
|
||||
let output = await microbundle({
|
||||
cwd: path.resolve(__dirname, 'fixtures/demo'),
|
||||
formats: 'es,cjs,umd'
|
||||
});
|
||||
|
||||
expect(strip(output)).toEqual(strip(`
|
||||
Build output to dist:
|
||||
225 B: demo.js
|
||||
225 B: demo.m.js
|
||||
295 B: demo.umd.js
|
||||
`));
|
||||
|
||||
let dist = await fs.readdir(path.resolve(__dirname, 'fixtures/demo/dist'));
|
||||
|
||||
expect(dist).toEqual([
|
||||
'demo.js',
|
||||
'demo.js.map',
|
||||
'demo.m.js',
|
||||
'demo.m.js.map',
|
||||
'demo.umd.js',
|
||||
'demo.umd.js.map'
|
||||
]);
|
||||
});
|
||||
});
|
||||
3
test/lib/util.js
Normal file
3
test/lib/util.js
Normal file
@ -0,0 +1,3 @@
|
||||
import stripAnsi from 'strip-ansi';
|
||||
|
||||
export const strip = s => stripAnsi(s).replace(/(?:^[\n\s]+|[\n\s]+$|(^|\n)\s+)/gm, '$1');
|
||||
31
test/ts-demo.test.js
Normal file
31
test/ts-demo.test.js
Normal file
@ -0,0 +1,31 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import { strip } from './lib/util';
|
||||
import microbundle from '../src/index';
|
||||
|
||||
describe('ts-demo', () => {
|
||||
it('should produce build files', async () => {
|
||||
let output = await microbundle({
|
||||
cwd: path.resolve(__dirname, 'fixtures/ts-demo'),
|
||||
formats: 'es,cjs,umd'
|
||||
});
|
||||
|
||||
expect(strip(output)).toEqual(strip(`
|
||||
Build output to dist:
|
||||
106 B: ts-demo.js
|
||||
106 B: ts-demo.m.js
|
||||
175 B: ts-demo.umd.js
|
||||
`));
|
||||
|
||||
let dist = await fs.readdir(path.resolve(__dirname, 'fixtures/ts-demo/dist'));
|
||||
|
||||
expect(dist).toEqual([
|
||||
'ts-demo.js',
|
||||
'ts-demo.js.map',
|
||||
'ts-demo.m.js',
|
||||
'ts-demo.m.js.map',
|
||||
'ts-demo.umd.js',
|
||||
'ts-demo.umd.js.map'
|
||||
]);
|
||||
});
|
||||
});
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"name": "ts-demo"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user