Skip to content

Commit

Permalink
add esm testrunner e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiAnAn committed Mar 23, 2021
1 parent 144f952 commit fbaf646
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
16 changes: 16 additions & 0 deletions e2e/__tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,20 @@ onNodeVersions('^12.17.0 || >=13.2.0', () => {
expect(json.numPassedTests).toBe(1);
});
});

describe('transform-esm-testrunner', () => {
const dir = path.resolve(
__dirname,
'../transform/transform-esm-testrunner',
);
test('runs test with native ESM', () => {
const {json, stderr} = runWithJson(dir, ['--no-cache'], {
nodeOptions: '--experimental-vm-modules',
});

expect(stderr).toMatch(/PASS/);
expect(json.success).toBe(true);
expect(json.numPassedTests).toBe(1);
});
});
});
10 changes: 10 additions & 0 deletions e2e/transform/transform-esm-testrunner/__tests__/add.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

it('should add two numbers', () => {
expect(1 + 1).toBe(2);
});
7 changes: 7 additions & 0 deletions e2e/transform/transform-esm-testrunner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "module",
"jest": {
"rootDir": "./",
"testRunner": "<rootDir>/test-runner.mjs"
}
}
33 changes: 33 additions & 0 deletions e2e/transform/transform-esm-testrunner/test-runner.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* 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';

export default async function testRunner(
globalConfig,
config,
environment,
runtime,
testPath,
) {
return {
...createEmptyTestResult(),
numPassingTests: 1,
testFilePath: testPath,
testResults: [
{
ancestorTitles: [],
duration: 2,
failureMessages: [],
fullName: 'sample test',
location: null,
numPassingAsserts: 1,
status: 'passed',
title: 'sample test',
},
],
};
}

0 comments on commit fbaf646

Please sign in to comment.