-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjapaFile.ts
More file actions
69 lines (58 loc) · 1.64 KB
/
Copy pathjapaFile.ts
File metadata and controls
69 lines (58 loc) · 1.64 KB
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
61
62
63
64
65
66
67
68
69
import 'reflect-metadata'
import { join } from 'path'
import getPort from 'get-port'
import japa from 'japa'
import sourceMapSupport from 'source-map-support'
import puppeteer from 'puppeteer'
process.env.NODE_ENV = 'testing'
process.env.ADONIS_ACE_CWD = join(__dirname)
sourceMapSupport.install({ handleUncaughtExceptions: false })
console.clear()
/**
* Configure test runner
*/
japa.configure({
files: getTestFiles(),
before: [
startBrowser,
startHttpServer,
],
after: [
closeBrowser,
closeDatabaseConnection,
],
bail: true,
timeout: 1000 * 10,
})
function getTestFiles() {
let testFilePath = process.argv.slice(2)[0]
if (!testFilePath) {
return 'tests/**/*.(spec|test).(ts|js)'
}
else {
return `tests/**/${testFilePath.replace(/(\.ts$|\.js)$/, '')}.(ts|js)`
}
}
async function startHttpServer() {
console.log('Launching Server...')
const { Ignitor } = await import('@adonisjs/core/build/src/Ignitor')
process.env.PORT = String(await getPort())
await new Ignitor(__dirname).httpServer().start()
global.SERVER_HOST = `http://localhost:${process.env.PORT}`
}
async function closeDatabaseConnection() {
// const { default: Database } = await import('@ioc:Adonis/Lucid/Database')
// await Database.manager.closeAll()
}
async function startBrowser() {
if (global.BROWSER) await closeBrowser()
console.log('Launching Puppeteer...')
global.BROWSER = await puppeteer.launch({
headless: true,
// slowMo: 100, // Slows down Puppeteer operations by the specified amount of milliseconds to aid debugging.
})
}
async function closeBrowser() {
await global.BROWSER?.close()
global.BROWSER = null
}