mirror of
https://github.com/developit/microbundle.git
synced 2026-01-25 14:06:50 +00:00
Merge pull request #59 from Andarist/snapshots
Auto generate tests with snapshots
This commit is contained in:
commit
004adc6d48
@ -69,6 +69,7 @@
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"directory-tree": "^2.0.0",
|
||||
"eslint": "^4.16.0",
|
||||
"eslint-config-developit": "^1.1.1",
|
||||
"fs-extra": "^5.0.0",
|
||||
|
||||
41
test/__snapshots__/index.test.js.snap
Normal file
41
test/__snapshots__/index.test.js.snap
Normal file
@ -0,0 +1,41 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`fixtures demo 1`] = `
|
||||
"demo
|
||||
dist
|
||||
demo.js
|
||||
demo.js.map
|
||||
demo.m.js
|
||||
demo.m.js.map
|
||||
demo.umd.js
|
||||
demo.umd.js.map
|
||||
src
|
||||
index.js
|
||||
two.js
|
||||
|
||||
|
||||
Build output to dist:
|
||||
225 B: demo.js
|
||||
225 B: demo.m.js
|
||||
295 B: demo.umd.js"
|
||||
`;
|
||||
|
||||
exports[`fixtures ts-demo 1`] = `
|
||||
"ts-demo
|
||||
dist
|
||||
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
|
||||
src
|
||||
car.ts
|
||||
index.ts
|
||||
|
||||
|
||||
Build output to dist:
|
||||
106 B: ts-demo.js
|
||||
106 B: ts-demo.m.js
|
||||
175 B: ts-demo.umd.js"
|
||||
`;
|
||||
@ -1,31 +0,0 @@
|
||||
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'
|
||||
]);
|
||||
});
|
||||
});
|
||||
39
test/index.test.js
Normal file
39
test/index.test.js
Normal file
@ -0,0 +1,39 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import dirTree from 'directory-tree';
|
||||
import { strip } from './lib/util';
|
||||
import microbundle from '../src/index';
|
||||
|
||||
const FIXTURES_DIR = `${__dirname}/fixtures`;
|
||||
|
||||
const times = (n, fn) => Array.from({ length: n }).map(i => fn(i));
|
||||
const join = (arr, delimiter = '') => arr.join(delimiter);
|
||||
const constant = konst => () => konst;
|
||||
|
||||
const printTree = (nodes, indentLevel = 0) => {
|
||||
const indent = join(times(indentLevel, constant(' ')));
|
||||
return join(nodes.map(node =>
|
||||
`${indent}${node.name}\n${node.type === 'directory' ? printTree(node.children, indentLevel + 1) : ''}`
|
||||
));
|
||||
};
|
||||
|
||||
describe('fixtures', () => {
|
||||
fs.readdirSync(FIXTURES_DIR).forEach(fixtureDir => {
|
||||
const fixturePath = path.resolve(path.join(FIXTURES_DIR, fixtureDir));
|
||||
|
||||
if (!fs.statSync(fixturePath).isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
it(fixtureDir, async () => {
|
||||
const output = await microbundle({
|
||||
cwd: path.resolve(fixturePath),
|
||||
formats: 'es,cjs,umd'
|
||||
});
|
||||
|
||||
const printedDir = printTree([dirTree(fixturePath)]);
|
||||
|
||||
expect(`${printedDir}\n\n${strip(output)}`).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,31 +0,0 @@
|
||||
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'
|
||||
]);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user