Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix esm can not get cjs named export problem
  • Loading branch information
WeiAnAn committed May 1, 2021
commit 409340e1cc651d2f6ce247a7b573c2f170dbf210
4 changes: 3 additions & 1 deletion e2e/esm-global-setup/setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import crypto from 'crypto';
import os from 'os';
import path from 'path';
import fs from 'graceful-fs';
import {createDirectory} from 'jest-util';
import jestUtil from 'jest-util';

const {createDirectory} = jestUtil;

const DIR = path.join(os.tmpdir(), 'jest-esm-global-setup');

Expand Down
4 changes: 3 additions & 1 deletion e2e/esm-global-teardown/teardown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import crypto from 'crypto';
import os from 'os';
import path from 'path';
import fs from 'graceful-fs';
import {createDirectory} from 'jest-util';
import jestUtil from 'jest-util';

const {createDirectory} = jestUtil;

const DIR = path.join(os.tmpdir(), 'jest-esm-global-teardown');

Expand Down
4 changes: 3 additions & 1 deletion e2e/transform/transform-esm-runner/runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import throat from 'throat';
import {createEmptyTestResult} from '@jest/test-result';
import testResult from '@jest/test-result';

const {createEmptyTestResult} = testResult;
Comment on lines +8 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import testResult from '@jest/test-result';
const {createEmptyTestResult} = testResult;
import {createEmptyTestResult} from '@jest/test-result';

does this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.
Because ts will compile to common js modules, and export using Object.defineProperty with getter.
ESM named import from CJS module only support exports.name = value way. esm commonjs namespaces

CI error log

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested. It worked.


export default class BaseTestRunner {
constructor(globalConfig, context) {
Expand Down
4 changes: 3 additions & 1 deletion e2e/transform/transform-esm-testrunner/test-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {createEmptyTestResult} from '@jest/test-result';
import testResult from '@jest/test-result';

const {createEmptyTestResult} = testResult;

export default async function testRunner(
globalConfig,
Expand Down