|
| 1 | +/** |
| 2 | + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * @flow |
| 7 | + */ |
| 8 | +'use strict'; |
| 9 | + |
| 10 | +const fs = require('fs'); |
| 11 | +const mkdirp = require('mkdirp'); |
| 12 | +const os = require('os'); |
| 13 | +const path = require('path'); |
| 14 | +const runJest = require('../runJest'); |
| 15 | +const {cleanup} = require('../utils'); |
| 16 | + |
| 17 | +const DIR = path.join(os.tmpdir(), 'jest'); |
| 18 | + |
| 19 | +beforeEach(() => cleanup(DIR)); |
| 20 | +afterAll(() => cleanup(DIR)); |
| 21 | + |
| 22 | +test('globalTeardown is triggered once after all test suites', () => { |
| 23 | + mkdirp.sync(DIR); |
| 24 | + const path = require('path'); |
| 25 | + const teardownPath = path.resolve( |
| 26 | + __dirname, |
| 27 | + '../global_teardown/teardown.js', |
| 28 | + ); |
| 29 | + const result = runJest.json('global_teardown', [ |
| 30 | + `--globalTeardown=${teardownPath}`, |
| 31 | + ]); |
| 32 | + expect(result.status).toBe(0); |
| 33 | + const files = fs.readdirSync(DIR); |
| 34 | + expect(files).toHaveLength(1); |
| 35 | + const teardown = fs.readFileSync(path.join(DIR, files[0]), 'utf8'); |
| 36 | + expect(teardown).toBe('teardown'); |
| 37 | +}); |
0 commit comments