Skip to content

Commit

Permalink
😱 🚀 🎨 tests: use truncate instead of database deletion (#8119)
Browse files Browse the repository at this point in the history
* 😱  🚀  🎨  tests: use truncate instead of delete the database

refs #7718, refs #7470

- should bring massive speed improvement
- could also fix random test failures (e.g. sqlite database is busy)

* gruntfile: add knex-migrator command in test-setup
  • Loading branch information
kirrg001 authored and ErisDS committed Mar 9, 2017
1 parent feaa25d commit f8c51ac
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 93 deletions.
15 changes: 14 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

// jshint unused: false
var overrides = require('./core/server/overrides'),
config = require('./core/server/config'),
_ = require('lodash'),
chalk = require('chalk'),
fs = require('fs-extra'),
KnexMigrator = require('knex-migrator'),
knexMigrator = new KnexMigrator({
knexMigratorFilePath: config.get('paths:appRoot')
}),

path = require('path'),

escapeChar = process.platform.match(/^win/) ? '^' : '\\',
Expand Down Expand Up @@ -446,6 +452,13 @@ var overrides = require('./core/server/overrides'),
});
});

/**
* Ensures the target database get's automatically created.
*/
grunt.registerTask('knex-migrator', function () {
return knexMigrator.init({noScripts: true});
});

// ### Validate
// **Main testing task**
//
Expand Down Expand Up @@ -499,7 +512,7 @@ var overrides = require('./core/server/overrides'),
// ### test-setup *(utility)(
// `grunt test-setup` will run all the setup tasks required for running tests
grunt.registerTask('test-setup', 'Setup ready to run tests',
['clean:test', 'setTestEnv']
['knex-migrator', 'clean:test', 'setTestEnv']
);

// ### Unit Tests *(sub task)*
Expand Down
10 changes: 6 additions & 4 deletions core/test/functional/routes/frontend_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('Frontend Routing', function () {
}

function addPosts(done) {
testUtils.initData().then(function () {
testUtils.clearData().then(function () {
return testUtils.initData();
}).then(function () {
return testUtils.fixtures.insertPostsAndTags();
}).then(function () {
done();
Expand Down Expand Up @@ -493,10 +495,10 @@ describe('Frontend Routing', function () {
});

describe('Site Map', function () {
before(testUtils.teardown);

before(function (done) {
testUtils.initData().then(function () {
testUtils.clearData().then(function () {
return testUtils.initData();
}).then(function () {
return testUtils.fixtures.insertPostsAndTags();
}).then(function () {
done();
Expand Down
3 changes: 3 additions & 0 deletions core/test/utils/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function forkGhost(newConfig) {
.then(function (_port) {
port = _port;

return knexMigrator.reset();
})
.then(function () {
return knexMigrator.init();
})
.then(function () {
Expand Down
Loading

0 comments on commit f8c51ac

Please sign in to comment.