我想创建SQL Server数据库的快照,然后在“所有固定装置”运行之后将其还原。
我可以在每个固定装置之后通过钩住固定装置后进行操作。但是,这在运行测试时会引起问题,因为还原后数据库可能仍处于过渡状态。所以我宁愿在所有固定装置之后做。
答案 0 :(得分:1)
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.
答案 1 :(得分:1)
您还可以使用TestCafe Programming Interface API。 TestCafe Runner class返回Promise对象。完成所有测试/固定后,您可以使用此对象运行自定义清理代码。
这是一个例子:
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();
});