-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (58 loc) · 1.67 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
53
54
55
56
57
58
59
60
const { assert } = require('@japa/assert')
const { apiClient } = require('@japa/api-client')
const { specReporter } = require('@japa/spec-reporter')
const { runFailedTests } = require('@japa/run-failed-tests')
const { browserClient } = require('@japa/browser-client')
function presetSails() {
return async function (config, runner, { TestContext }) {
runner.onSuite((suite) => {
suite.setup(async () => {
if (
suite.name == 'functional' ||
suite.name == 'e2e' ||
suite.name == 'browser'
) {
const sails = await startApp({ environment: 'test' })
TestContext.macro('route', function (target, routeParams) {
let url = sails.getUrlFor(target)
if (routeParams) {
url = interpolateUrl(url, routeParams)
function interpolateUrl(url, replaceMap) {
return url
.split('/')
.map((part) =>
part.startsWith(':') ? replaceMap[part.substr(1)] : part
)
.join('/')
}
}
return url
})
return async () => await sails.lower()
}
await startApp({ environment: 'test' }, 'load')
})
})
}
}
function startApp(options, method = 'lift') {
return new Promise((resolve, reject) => {
const Sails = require('sails').constructor
const sails = new Sails()
sails[method](options, (error, sails) => {
if (error) {
reject(error)
} else {
resolve(sails)
}
})
})
}
module.exports = {
presetSails,
assert,
apiClient,
browserClient,
specReporter,
runFailedTests
}