forked from platformatic/platformatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients.test.js
112 lines (84 loc) · 3.1 KB
/
clients.test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict'
const assert = require('node:assert')
const { test } = require('node:test')
const { join } = require('node:path')
const { rm } = require('node:fs/promises')
const { request } = require('undici')
const { compile } = require('../lib/compile')
const { buildServer } = require('..')
// require('./helper')
test('client is loaded', async (t) => {
const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
t.after(async () => {
await app1.close()
})
await app1.start()
process.env.PLT_CLIENT_URL = app1.url
const app2 = await buildServer(join(__dirname, '..', 'fixtures', 'hello-client', 'platformatic.service.json'))
t.after(async () => {
await app2.close()
})
await app2.start()
const res = await request(`${app2.url}/`)
assert.strictEqual(res.statusCode, 200, 'status code')
const data = await res.body.json()
assert.deepStrictEqual(data, { hello: 'world' })
})
test('client is loaded (ts)', async (t) => {
const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
t.after(async () => {
await app1.close()
})
await app1.start()
process.env.PLT_CLIENT_URL = app1.url
const targetDir = join(__dirname, '..', 'fixtures', 'hello-client-ts')
try {
await rm(join(targetDir, 'dist'), { recursive: true })
} catch {}
console.time('compile')
await compile(targetDir, { server: { logger: { level: 'warn' } } })
console.timeEnd('compile')
const app2 = await buildServer(join(targetDir, 'platformatic.service.json'))
t.after(async () => {
await app2.close()
})
await app2.start()
const res = await request(`${app2.url}/`)
assert.strictEqual(res.statusCode, 200, 'status code')
const data = await res.body.json()
assert.deepStrictEqual(data, { hello: 'world' })
})
test('client is loaded dependencyless', async (t) => {
const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
t.after(async () => {
await app1.close()
})
await app1.start()
process.env.PLT_CLIENT_URL = app1.url
const app2 = await buildServer(join(__dirname, '..', 'fixtures', 'hello-client-without-deps', 'platformatic.service.json'))
t.after(async () => {
await app2.close()
})
await app2.start()
const res = await request(`${app2.url}/`)
assert.strictEqual(res.statusCode, 200, 'status code')
const data = await res.body.json()
assert.deepStrictEqual(data, { hello: 'world' })
})
test('client is loaded before plugins', async (t) => {
const app1 = await buildServer(join(__dirname, '..', 'fixtures', 'hello', 'warn-log.service.json'))
t.after(async () => {
await app1.close()
})
await app1.start()
process.env.PLT_CLIENT_URL = app1.url
const app2 = await buildServer(join(__dirname, '..', 'fixtures', 'hello-client-from-plugin', 'platformatic.service.json'))
t.after(async () => {
await app2.close()
})
await app2.start()
const res = await request(`${app2.url}/`)
assert.strictEqual(res.statusCode, 200, 'status code')
const data = await res.body.json()
assert.deepStrictEqual(data, { hello: 'world' })
})