diff --git a/package.json b/package.json index 0d371fe1..1e380e35 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap new file mode 100644 index 00000000..791839b8 --- /dev/null +++ b/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" +`; diff --git a/test/demo.test.js b/test/demo.test.js deleted file mode 100644 index 4365d222..00000000 --- a/test/demo.test.js +++ /dev/null @@ -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' - ]); - }); -}); diff --git a/test/index.test.js b/test/index.test.js new file mode 100644 index 00000000..c5f58269 --- /dev/null +++ b/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(); + }); + }); +}); diff --git a/test/ts-demo.test.js b/test/ts-demo.test.js deleted file mode 100644 index 445a0270..00000000 --- a/test/ts-demo.test.js +++ /dev/null @@ -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' - ]); - }); -});