mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Revert "Added global setup to reset DB before test run"
This reverts commit d50fb7c922
.
This commit is contained in:
parent
d50fb7c922
commit
2cc2d114f4
4 changed files with 10 additions and 48 deletions
10
package.json
10
package.json
|
@ -26,20 +26,20 @@
|
||||||
"setup": "yarn install && knex-migrator init && grunt symlink && grunt init || (exit 0)",
|
"setup": "yarn install && knex-migrator init && grunt symlink && grunt init || (exit 0)",
|
||||||
"main": "grunt shell:main && grunt subgrunt:init",
|
"main": "grunt shell:main && grunt subgrunt:init",
|
||||||
"build": "grunt build",
|
"build": "grunt build",
|
||||||
"test": "mocha --require=./test/utils/db-overrides.js --exit --trace-warnings --recursive --extension=test.js --timeout=60000",
|
"test": "mocha --require=./test/utils/overrides.js --exit --trace-warnings --recursive --extension=test.js --timeout=60000",
|
||||||
"test:all": "yarn test:unit && yarn test:integration && yarn test:e2e && yarn lint",
|
"test:all": "yarn test:unit && yarn test:integration && yarn test:e2e && yarn lint",
|
||||||
"test:debug": "DEBUG=ghost:test* yarn test",
|
"test:debug": "DEBUG=ghost:test* yarn test",
|
||||||
"test:unit": "c8 yarn test:unit:base",
|
"test:unit": "c8 yarn test:unit:base",
|
||||||
"test:unit:base": "mocha --require=./test/utils/overrides.js --exit --trace-warnings --recursive --extension=test.js './test/unit' --timeout=2000",
|
"test:unit:base": "mocha --require=./test/utils/overrides.js --exit --trace-warnings --recursive --extension=test.js './test/unit' --timeout=2000",
|
||||||
"test:integration": "mocha --require=./test/utils/db-overrides.js --exit --trace-warnings --recursive --extension=test.js './test/integration' --timeout=5000",
|
"test:integration": "mocha --require=./test/utils/overrides.js --exit --trace-warnings --recursive --extension=test.js './test/integration' --timeout=5000",
|
||||||
"test:e2e": "mocha --require=./test/utils/db-overrides.js --exit --trace-warnings --recursive --extension=test.js './test/e2e-api' './test/e2e-frontend' './test/e2e-server' --timeout=10000",
|
"test:e2e": "mocha --require=./test/utils/overrides.js --exit --trace-warnings --recursive --extension=test.js './test/e2e-api' './test/e2e-frontend' './test/e2e-server' --timeout=10000",
|
||||||
"test:regression": "mocha --require=./test/utils/db-overrides.js --exit --trace-warnings --recursive --extension=test.js './test/regression' --timeout=60000",
|
"test:regression": "mocha --require=./test/utils/overrides.js --exit --trace-warnings --recursive --extension=test.js './test/regression' --timeout=60000",
|
||||||
"test:browser": "playwright test --browser=all test/e2e-browser",
|
"test:browser": "playwright test --browser=all test/e2e-browser",
|
||||||
"test:ci": "yarn test:e2e -b && yarn test:integration -b && yarn test:regression -b",
|
"test:ci": "yarn test:e2e -b && yarn test:integration -b && yarn test:regression -b",
|
||||||
"test:unit:slow": "yarn test:unit --reporter=mocha-slow-test-reporter",
|
"test:unit:slow": "yarn test:unit --reporter=mocha-slow-test-reporter",
|
||||||
"test:int:slow": "yarn test:integration --reporter=mocha-slow-test-reporter",
|
"test:int:slow": "yarn test:integration --reporter=mocha-slow-test-reporter",
|
||||||
"test:e2e:slow": "yarn test:e2e --reporter=mocha-slow-test-reporter",
|
"test:e2e:slow": "yarn test:e2e --reporter=mocha-slow-test-reporter",
|
||||||
"test:reg:slow": "yarn test:regression --reporter=mocha-slow-test-reporter",
|
"test:reg:slow": "mocha --require=./test/utils/overrides.js --exit --trace-warnings --recursive --extension=test.js './test/regression' --timeout=60000 --reporter=mocha-slow-test-reporter",
|
||||||
"lint:server": "eslint --ignore-path .eslintignore 'core/server/**/*.js' 'core/*.js' '*.js'",
|
"lint:server": "eslint --ignore-path .eslintignore 'core/server/**/*.js' 'core/*.js' '*.js'",
|
||||||
"lint:shared": "eslint --ignore-path .eslintignore 'core/shared/**/*.js'",
|
"lint:shared": "eslint --ignore-path .eslintignore 'core/shared/**/*.js'",
|
||||||
"lint:frontend": "eslint --ignore-path .eslintignore 'core/frontend/**/*.js'",
|
"lint:frontend": "eslint --ignore-path .eslintignore 'core/frontend/**/*.js'",
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
* This overrides file should be used for all tests that use the DB
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = require('./overrides');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Global Setup
|
|
||||||
* Guaranteed to only ever run once regardless of whether
|
|
||||||
* mocha is run in serial or parallel
|
|
||||||
*/
|
|
||||||
module.exports.mochaGlobalSetup = async function () {
|
|
||||||
// Actually delete the database so we start afresh
|
|
||||||
// This protects against DB errors after an aborted test run
|
|
||||||
// This technically only needs to happen before DB-related tests
|
|
||||||
await require('./db-utils').destroy();
|
|
||||||
};
|
|
|
@ -17,10 +17,6 @@ const urlServiceUtils = require('./url-service-utils');
|
||||||
|
|
||||||
const dbHash = Date.now();
|
const dbHash = Date.now();
|
||||||
|
|
||||||
module.exports.destroy = async () => {
|
|
||||||
await knexMigrator.reset({force: true});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.reset = async ({truncate} = {truncate: false}) => {
|
module.exports.reset = async ({truncate} = {truncate: false}) => {
|
||||||
// Only run this copy in CI until it gets fleshed out
|
// Only run this copy in CI until it gets fleshed out
|
||||||
if (process.env.CI && config.get('database:client') === 'sqlite3') {
|
if (process.env.CI && config.get('database:client') === 'sqlite3') {
|
||||||
|
@ -41,21 +37,12 @@ module.exports.reset = async ({truncate} = {truncate: false}) => {
|
||||||
await fs.copyFile(filename, filenameOrig);
|
await fs.copyFile(filename, filenameOrig);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug('not CI');
|
|
||||||
if (truncate) {
|
if (truncate) {
|
||||||
debug('truncate mode');
|
// Perform a fast reset by tearing down all the tables and
|
||||||
// Perform a fast reset by tearing down all the tables and inserting the fixtures
|
// inserting the fixtures
|
||||||
try {
|
await module.exports.teardown();
|
||||||
await module.exports.teardown();
|
await knexMigrator.init({only: 2});
|
||||||
await knexMigrator.init({only: 2});
|
|
||||||
} catch (err) {
|
|
||||||
// If it fails, try a normal reset and init
|
|
||||||
debug('teardown failed, reset and init');
|
|
||||||
await knexMigrator.reset({force: true});
|
|
||||||
await knexMigrator.init();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
debug('reset and init');
|
|
||||||
// Do a full database reset + initialisation
|
// Do a full database reset + initialisation
|
||||||
await knexMigrator.reset({force: true});
|
await knexMigrator.reset({force: true});
|
||||||
await knexMigrator.init();
|
await knexMigrator.init();
|
||||||
|
@ -150,9 +137,6 @@ module.exports.teardown = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
debug('Database teardown end');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'testing';
|
process.env.NODE_ENV = process.env.NODE_ENV || 'testing';
|
||||||
|
|
||||||
/**
|
|
||||||
* This overrides file should be used for all tests that DO NOT use the DB - e.g. unit tests
|
|
||||||
*/
|
|
||||||
|
|
||||||
process.env.WEBHOOK_SECRET = process.env.WEBHOOK_SECRET || 'TEST_STRIPE_WEBHOOK_SECRET';
|
process.env.WEBHOOK_SECRET = process.env.WEBHOOK_SECRET || 'TEST_STRIPE_WEBHOOK_SECRET';
|
||||||
|
|
||||||
require('../../core/server/overrides');
|
require('../../core/server/overrides');
|
||||||
|
|
||||||
const {mochaHooks} = require('@tryghost/express-test').snapshot;
|
const {mochaHooks} = require('@tryghost/express-test').snapshot;
|
||||||
module.exports.mochaHooks = mochaHooks;
|
exports.mochaHooks = mochaHooks;
|
||||||
|
|
Loading…
Add table
Reference in a new issue