Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
clean up error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Apr 18, 2019
1 parent 708731e commit 5581e4f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 34 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
@@ -0,0 +1,7 @@
{
"printWidth": 80,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "always"
}
56 changes: 22 additions & 34 deletions cypress/plugins/index.js
@@ -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)
])
}
})
}

0 comments on commit 5581e4f

Please sign in to comment.