"globalTeardown" and "globalSetup" process behavior not as expected
See original GitHub issueDo you want to request a feature or report a bug? Somewhere between feature enhancement and a bug.
What is the current behavior? Scenario A. You pass a globalSetup script in your config the result is:
- Tests run fine
- Watch works
- Regular test run never “finishes”/process never exits (an issue with things that automatically run tests)
Scenario B. You pass a globalSetup and globalTeardown scripts, with the teardown running a process.exit() when it 's done, the result is:
- Test run fine
- Watch kills itself
- Regular test run finishes if you manually process.exit()
Scenario C. You pass a globalSetup and globalTeardown scripts, with the teardown not running a process.exit() when it 's done - resulting in the same behavior as Scenario A.
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install
and yarn test
.
Believe you can reproduce with any globalSetup/Teardown scripts - mine are async - here they are for reference:
globalSetup
const Sequelize = require('sequelize');
const Umzug = require('umzug');
const path = require('path');
const env = 'test';
const config = require('./src/dbConfig')[env];
const sequelize = new Sequelize(config);
const create = async () => {
const createConfig = { ...config };
delete createConfig.database;
const createSequelize = new Sequelize(createConfig);
await createSequelize.query(`CREATE DATABASE ${createSequelize.getQueryInterface().quoteIdentifier(config.database)}`, {
type: createSequelize.QueryTypes.RAW
}).catch(e => console.error(e));
};
const migrate = async () => {
const umzug = new Umzug({
storage: 'sequelize',
storageOptions: {
sequelize
},
migrations: {
params: [
sequelize.getQueryInterface(),
Sequelize
],
path: path.join(__dirname, './src/migrations')
}
});
await umzug.up();
};
const seed = async () => {
const umzug = new Umzug({
storage: 'sequelize',
storageOptions: {
sequelize
},
migrations: {
params: [
sequelize.getQueryInterface(),
Sequelize
],
path: path.join(__dirname, './src/testSeeders')
}
});
await umzug.up();
};
module.exports = async () => {
await create()
.then(() => migrate()
.then(() => seed())
);
};
globalTeardown
const Sequelize = require('sequelize');
const env = 'test';
const config = require('./src/dbConfig')[env];
const drop = async () => {
const dropConfig = { ...config };
delete dropConfig.database;
const dropSequelize = new Sequelize(dropConfig);
await dropSequelize.query(`DROP DATABASE ${dropSequelize.getQueryInterface().quoteIdentifier(config.database)}`, {
type: dropSequelize.QueryTypes.RAW
}).catch(e => console.error(e));
};
module.exports = async () => {
await drop()
.then(() => process.exit());
};
What is the expected behavior?
Something either passed to teardown to let users of this awesome config/functionality to be able to safely exit tests or any other proposal that rectifies behavior. Or I’m an idiot and there are already things to hook into to correct this behavior - just haven’t been able to find anything after scouring the internets.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
"jest": {
"moduleDirectories": [
"node_modules",
"src"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "identity-obj-proxy"
},
"testEnvironment": "jsdom",
"snapshotSerializers": [
"enzyme-to-json/serializer",
"jest-glamor-react"
],
"collectCoverageFrom": [
"src/**/*.js",
"!src/*.js",
"!src/state/_stubs/*",
"!src/models/*",
"!src/seeders/*",
"!src/testSeeders/*",
"!src/migrations/*"
],
"coverageReporters": [
"json-summary",
"lcov"
],
"coverageThreshold": {
"global": {
"lines": 10
}
},
"setupTestFrameworkScriptFile": "./testSetup.js",
"globalSetup": "./testGlobalSetup.js",
"globalTeardown": "./testGlobalTeardown.js"
},
jest@22.0.4 yarn@1.3.2 node@8.7.0 OSX@10.12.6
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top GitHub Comments
You can use
--forceExit
in order to not allow Jest to wait for handles keeping the process open.Normal errors keeping the process open are either
setTimeout
orsetInterval
without an.unref()
call (if using node), or some server/db-connection not closed. I’m not sure what’s the best way to figure out what’s keeping the process open, ideas would be great! why-is-node-running used to work pretty good, but not in later versions of node.If you find some tool capable of tracking down the open handle, please share it. Maybe we could link to it from the docs
@SimenB Will do - might not get to it today but will get a PR up as soon as I can