Skip to content

Commit

Permalink
fix: add tests for canonicalizing a module
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLey committed May 22, 2022
1 parent 1660462 commit 0264c7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/unit/fixtures/module.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default 123;

export const foo = 'abc';
export const bar = true;
18 changes: 18 additions & 0 deletions test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
'use strict';

var utils = require('../../lib/utils');
const esmUtils = require('../../lib/nodejs/esm-utils');
const Path = require('node:path');
var sinon = require('sinon');

describe('lib/utils', function () {
Expand Down Expand Up @@ -288,6 +290,22 @@ describe('lib/utils', function () {
].join('\n');
expect(stringify(expected), 'to be', actual);
});

it('should represent modules', async function () {
const expected = await esmUtils.requireOrImport(
Path.join(__dirname, './fixtures/module.mjs')
);
const actual = [
'{',
' "[Symbol.toStringTag]": "Module"',
' "bar": true',
' "default": 123',
' "foo": "abc"',
'}'
].join('\n');

expect(stringify(expected), 'to be', actual);
});
});

it('should canonicalize the object', function () {
Expand Down

0 comments on commit 0264c7f

Please sign in to comment.