This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"printWidth": 80, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"arrowParens": "always" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,31 @@ | ||
const { join } = require("path"); | ||
const knexFactory = require("knex"); | ||
const { join } = require('path') | ||
const knexFactory = require('knex') | ||
|
||
module.exports = (on, config) => { | ||
// `on` is used to hook into various events Cypress emits | ||
// `config` is the resolved Cypress config | ||
on("task", { | ||
deleteAllArticles() { | ||
on('task', { | ||
deleteAllArticles () { | ||
const filename = join(__dirname, '..', '..', 'server', '.tmp.db') | ||
const knex = knexFactory({ | ||
client: "sqlite3", | ||
client: 'sqlite3', | ||
connection: { | ||
filename: join(__dirname, "..", "..", "server", ".tmp.db") | ||
filename | ||
}, | ||
useNullAsDefault: true | ||
}); | ||
}) | ||
// if we are trying to truncate a non-existing table | ||
// that is ok - the server API will create them | ||
const onError = err => | ||
err.toString().includes('no such table') ? null : Promise.reject(err) | ||
|
||
// truncates all tables created by previous tests | ||
// or manually by using the application | ||
return Promise.all([ | ||
knex | ||
.truncate("Articles") | ||
.catch(err => | ||
err.toString().includes("no such table") | ||
? undefined | ||
: Promise.reject(err) | ||
), | ||
knex | ||
.truncate("ArticleTags") | ||
.catch(err => | ||
err.toString().includes("no such table") | ||
? undefined | ||
: Promise.reject(err) | ||
), | ||
, | ||
knex | ||
.truncate("Comments") | ||
.catch(err => | ||
err.toString().includes("no such table") | ||
? undefined | ||
: Promise.reject(err) | ||
) | ||
]); | ||
}, | ||
registerNewUserIfNeeded() {} | ||
}); | ||
}; | ||
knex.truncate('Articles').catch(onError), | ||
knex.truncate('ArticleTags').catch(onError), | ||
knex.truncate('Comments').catch(onError) | ||
]) | ||
} | ||
}) | ||
} |