-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweb-test-runner.config.mjs
102 lines (95 loc) · 2.96 KB
/
web-test-runner.config.mjs
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
import { OAuth2Server } from 'oauth2-mock-server';
import getPort, {portNumbers} from 'get-port';
import pkg from './test/oauth2/ServerMock.js';
const { CodeServerMock } = pkg;
/** @typedef {import('@web/test-runner').TestRunnerConfig} TestRunnerConfig */
const oauth2server = new OAuth2Server();
let oauth2env;
export default /** @type TestRunnerConfig */ ({
files: 'test/**/*.test.js',
// files: 'test/variables/*.test.js',
nodeResolve: true,
concurrency: 1,
testFramework: {
config: {
timeout: 5000,
}
},
plugins: [
{
name: 'mock-api',
serve(context) {
if (context.path === '/test/env.js') {
const data = {
oauth2: oauth2env,
};
return `export default ${JSON.stringify(data)}`;
}
if (context.path === '/oauth2/auth-code') {
return CodeServerMock.authRequest(context.request);
}
if (context.path === '/oauth2/token') {
return CodeServerMock.tokenRequest(context);
}
if (context.path === '/oauth2/auth-code-custom') {
return CodeServerMock.authRequestCustom(context.request);
}
if (context.path === '/oauth2/token-custom') {
return CodeServerMock.tokenRequestCustom(context);
}
if (context.path === '/oauth2/password') {
return CodeServerMock.tokenPassword(context);
}
if (context.path === '/oauth2/client-credentials') {
return CodeServerMock.tokenClientCredentials(context);
}
if (context.path === '/oauth2/client-credentials-header') {
return CodeServerMock.tokenClientCredentialsHeader(context);
}
if (context.path === '/oauth2/custom-grant') {
return CodeServerMock.tokenCustomGrant(context);
}
if (context.path === '/empty-response') {
return '';
}
return undefined;
},
},
// servers
{
name: 'servers',
async serverStart() {
const port = await getPort({ port: portNumbers(8000, 8100) });
await oauth2server.issuer.keys.generate('RS256');
await oauth2server.start(port, 'localhost');
oauth2env = {
port,
issuer: oauth2server.issuer.url,
};
},
async serverStop() {
await oauth2server.stop();
},
},
],
middleware: [
function implicitAuth(context, next) {
if (context.path === '/oauth2/auth-implicit') {
return CodeServerMock.authRequestImplicit(context);
}
if (context.path === '/oauth2/auth-implicit-custom') {
return CodeServerMock.authRequestImplicitCustom(context);
}
if (context.path === '/oauth2/auth-implicit-invalid-state') {
return CodeServerMock.authRequestImplicitStateError(context);
}
return next();
}
],
// testRunnerHtml: testFramework =>
// `<html>
// <body>
// <script type="module" src="${testFramework}"></script>
// </body>
// </html>`,
})