forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal_teardown.test.js
More file actions
36 lines (32 loc) · 1.02 KB
/
global_teardown.test.js
File metadata and controls
36 lines (32 loc) · 1.02 KB
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
/**
* Copyright (c) 2014-present, Facebook, Inc. 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.
* @flow
*/
'use strict';
const fs = require('fs');
const mkdirp = require('mkdirp');
const os = require('os');
const path = require('path');
const runJest = require('../runJest');
const {cleanup} = require('../utils');
const DIR = path.join(os.tmpdir(), 'jest_global_teardown');
beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
test('globalTeardown is triggered once after all test suites', () => {
mkdirp.sync(DIR);
const teardownPath = path.resolve(
__dirname,
'../global_teardown/teardown.js',
);
const result = runJest.json('global_teardown', [
`--globalTeardown=${teardownPath}`,
]);
expect(result.status).toBe(0);
const files = fs.readdirSync(DIR);
expect(files).toHaveLength(1);
const teardown = fs.readFileSync(path.join(DIR, files[0]), 'utf8');
expect(teardown).toBe('teardown');
});