Add test for import default

This commit is contained in:
Convly 2022-10-27 17:16:26 +02:00
parent 4f3fdafe37
commit 94749e2eb6
4 changed files with 54 additions and 0 deletions

View File

@ -7,4 +7,5 @@ module.exports = {
...baseConfig,
displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
roots: [__dirname],
testMatch: ['<rootDir>/**/*.test.js'],
};

View File

@ -0,0 +1,8 @@
'use strict';
module.exports = {
foo: 'bar',
cb() {
return 42;
},
};

View File

@ -0,0 +1,11 @@
'use strict';
module.exports = {
__esModule: true,
default: {
foo: 'bar',
cb() {
return 42;
},
},
};

View File

@ -0,0 +1,34 @@
'use strict';
const path = require('path');
const importDefault = require('../../import-default');
const getPath = (file) => path.resolve(__dirname, file);
describe('Import Default', () => {
test('ESM', () => {
const content = importDefault(getPath('./esm'));
expect(content).toBeDefined();
expect(content).toMatchObject(
expect.objectContaining({
foo: 'bar',
cb: expect.any(Function),
})
);
expect(content.cb()).toBe(42);
});
test('CJS', () => {
const content = importDefault(getPath('./cjs'));
expect(content).toBeDefined();
expect(content).toMatchObject(
expect.objectContaining({
foo: 'bar',
cb: expect.any(Function),
})
);
expect(content.cb()).toBe(42);
});
});