Skip to content

Commit

Permalink
Auto generate tests with snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jan 24, 2018
1 parent d8d2bf0 commit c2627c7
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 62 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -68,6 +68,7 @@
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"directory-tree": "^2.0.0",
"eslint": "^4.15.0",
"eslint-config-developit": "^1.1.1",
"fs-extra": "^5.0.0",
Expand Down
41 changes: 41 additions & 0 deletions test/__snapshots__/index.test.js.snap
@@ -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"
`;
31 changes: 0 additions & 31 deletions test/demo.test.js

This file was deleted.

39 changes: 39 additions & 0 deletions test/index.test.js
@@ -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();
});
});
});
31 changes: 0 additions & 31 deletions test/ts-demo.test.js

This file was deleted.

0 comments on commit c2627c7

Please sign in to comment.