Skip to content

Commit

Permalink
(refactor): even better multi-entry test errors w/ toMatchObject
Browse files Browse the repository at this point in the history
- output is now like:
  Object {
    -   "foo.cjs.development.js": true,
    -   "foo.cjs.production.min.js": true,
        "foo.d.ts": true,
    -   "foo.esm.js": true,
    -   "foo.js": true,
        "index.cjs.development.js": true,
        "index.cjs.production.min.js": true,
        "index.d.ts": true,
        "index.esm.js": true,
        "index.js": true,
  }
  - super readable!!
  - and no extraneous files listed (e.g. .map, other directories, etc)
  • Loading branch information
agilgur5 committed Dec 31, 2019
1 parent a70469f commit 1ec46b1
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions test/tests/tsdx-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,27 @@ describe('tsdx build', () => {
'--entry src/subdir1/subdir1-2/index.ts',
'--entry src/**/*.ts',
'--format esm,cjs'].join(' '));
const outputFiles = shell.ls('-R', 'dist/');

function testEntryOutput (filename) {
expect(shell.test('-f', `dist/${filename}.js`)).toBeTruthy();
expect(
shell.test('-f', `dist/${filename}.cjs.development.js`)
).toBeTruthy();
expect(
shell.test('-f', `dist/${filename}.cjs.production.min.js`)
).toBeTruthy();
expect(shell.test('-f', `dist/${filename}.esm.js`)).toBeTruthy();
expect(shell.test('-f', `dist/${filename}.d.ts`)).toBeTruthy();
function arrToDict (arr) {
return arr.reduce((dict, elem) => {
dict[elem] = true;
return dict;
}, {});
}

testEntryOutput('index')
testEntryOutput('foo')
testEntryOutput('subdir1/subdir1-2/index')
testEntryOutput('subdir1/glob')
const outputDict = arrToDict(outputFiles);

const entries = ['index', 'foo', 'subdir1/subdir1-2/index', 'subdir1/glob'];
const expected = entries.reduce((dict, entry) => {
dict[`${entry}.js`] = true;
dict[`${entry}.cjs.development.js`] = true;
dict[`${entry}.cjs.production.min.js`] = true;
dict[`${entry}.esm.js`] = true;
dict[`${entry}.d.ts`] = true;
return dict;
}, {});

expect(outputDict).toMatchObject(expected);

expect(output.code).toBe(0);
});
Expand Down

0 comments on commit 1ec46b1

Please sign in to comment.