/
testEnvironmentEsm.test.ts
39 lines (33 loc) · 1.14 KB
/
testEnvironmentEsm.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* 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 {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {onNodeVersions} from '@jest/test-utils';
import {cleanup} from '../Utils';
import runJest from '../runJest';
const DIR = tmpdir() + '/jest-test-environment-esm';
beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
onNodeVersions('^12.16.0 || >=13.7.0', () => {
it('triggers setup/teardown hooks', () => {
const testDir = path.resolve(
__dirname,
'..',
'test-environment-esm',
'__tests__',
);
const testFile = path.join(testDir, 'custom.test.js');
const result = runJest('test-environment-esm', [], {
nodeOptions: '--experimental-vm-modules --no-warnings',
});
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain(`TestEnvironment.setup: ${testFile}`);
const teardown = fs.readFileSync(DIR + '/teardown', 'utf8');
expect(teardown).toBe('teardown');
});
});