Reputation: 2110
I want to create a snapshot of the SQL server DB and then restore it after "all the fixtures" are run.
I can do it after every fixture through .after hook in a fixture. However, that is causing issues while running tests since the DB may be still in transition after a restore. So I would prefer to do it after all the fixtures.
Upvotes: 2
Views: 1522
Reputation: 483
Since you are usually running your tests in order, you could also make a fixture, call it 99_cleanup
and do your cleanup there.
Upvotes: 0
Reputation: 4274
You can also use the TestCafe Programming Interface API. The TestCafe Runner class returns a Promise object. You can use this object to run your custom cleanup code after all tests/fixtures are completed.
Here's an example:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/fixture1.js', 'tests/fixture2.js', 'tests/fixture3.js'])
.browsers(['chrome', 'safari'])
.run();
})
.then(failedCount => {
// Clean up your database here...
testcafe.close();
});
Upvotes: 1
Reputation: 2110
I have found a workaround for now. The workaround is:
"create-ss": "ts-node ./create-snapshot.ts"
, "restore-ss": "ts-node ./restore-snapshot.ts"
npm run create-ss;npm run test-chrome-hl;npm run restore-ss
. This runs the commands sequentially in Powershell. In other terminals you may need to use && or something else instead of ;. I can avoid "npm run create-ss" by using the .before hook of the fixture by keeping track of a variable to ensure it runs only once. However I cannot do a similar approach when the last test gets executed.
Its a bit of a pain to remember the three commands but I dont see another way so far.
Upvotes: 1