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 a643d4a commit 3401e51
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions test/tests/tsdx-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,27 @@ describe('tsdx build', () => {
'--entry src/subdir1/subdir1-2/index.ts',
'--entry src/**/*.ts',
'--format esm,cjs'].join(' '));

const entries = ['index', 'foo', 'subdir1/subdir1-2/index', 'subdir1/glob'];
const outputFiles = shell.ls('-R', 'dist/');

for (const entry of entries) {
expect(outputFiles).toContain(`${entry}.js`);
expect(outputFiles).toContain(`${entry}.cjs.development.js`);
expect(outputFiles).toContain(`${entry}.cjs.production.min.js`);
expect(outputFiles).toContain(`${entry}.esm.js`);
expect(outputFiles).toContain(`${entry}.d.ts`);
function arrToDict (arr) {
return arr.reduce((dict, elem) => {
dict[elem] = true;
return dict;
}, {});
}
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 3401e51

Please sign in to comment.