Skip to content

Commit

Permalink
Tests: Test for serializing module object from file which failed to…
Browse files Browse the repository at this point in the history
… load [improve]
  • Loading branch information
overlookmotel committed Dec 23, 2023
1 parent 4345770 commit e4a4807
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/commonjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ describe('`module`', () => {
}
});

itSerializes('from another module where loading module threw', {
in: {
'index.js': `
try {
require('./other.js');
} catch {}
module.exports = require('./store.js').module;
`,
'other.js': `
const store = require('./store.js');
store.module = module;
module.exports = {x: 1};
throw new Error('foo');
`,
'store.js': 'module.exports = {};'
},
out: '{exports:{x:1}}',
validate(mod, {isOutput}) {
expect(mod).toBeObject();
if (isOutput) expect(mod).toHaveOwnPropertyNames(['exports']);
expect(mod.exports).toEqual({x: 1});
}
});

itSerializes('in scope of function', {
in: "'use strict';module.exports = () => module;",
out: '(()=>{const a={},b=(a=>()=>a)(a);a.exports=b;return b})()',
Expand Down

0 comments on commit e4a4807

Please sign in to comment.