-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
52 lines (49 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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() {
const filename = join(__dirname, '..', '..', 'server', '.tmp.db')
const knex = knexFactory({
client: 'sqlite3',
connection: {
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 which removes data left by previous tests
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() {},
})
}
require('@applitools/eyes-cypress')(module)