Skip to content

Commit 4b36084

Browse files
coolbuebniftyvictor
authored andcommitted
ci: unit-testing
1 parent 8aeedc6 commit 4b36084

File tree

122 files changed

+1733
-2405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1733
-2405
lines changed

.github/workflows/unit-test.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: "Unit Tests"
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
push:
10+
branches:
11+
- master
12+
- "v[0-9]+.[0-9]+"
13+
tags:
14+
- "(dev-)?v[0-9]+.[0-9]+.[0-9]+"
15+
16+
jobs:
17+
define-versions:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
fdiVersions: ${{ steps.versions.outputs.fdiVersions }}
21+
cdiVersions: ${{ steps.versions.outputs.cdiVersions }}
22+
nodeVersions: '["18.20", "20.19", "22.14"]'
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: supertokens/get-supported-versions-action@main
26+
id: versions
27+
with:
28+
has-fdi: true
29+
has-cdi: true
30+
31+
test:
32+
runs-on: ubuntu-latest
33+
needs: define-versions
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
node-version: ${{ fromJSON(needs.define-versions.outputs.nodeVersions) }}
38+
cdi-version: ${{ fromJSON(needs.define-versions.outputs.cdiVersions) }}
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: supertokens/get-versions-action@main
42+
id: versions
43+
with:
44+
driver-name: node
45+
cdi-version: ${{ matrix.cdi-version }}
46+
env:
47+
SUPERTOKENS_API_KEY: ${{ secrets.SUPERTOKENS_API_KEY }}
48+
- uses: actions/setup-node@v4
49+
with:
50+
node-version: ${{ matrix.node-version }}
51+
- name: Install dependencies
52+
run: |
53+
npm install
54+
- name: Run unit tests
55+
run: |
56+
docker compose up --wait
57+
npm run test
58+
docker compose down
59+
env:
60+
SUPERTOKENS_CORE_VERSION: ${{ steps.versions.outputs.coreVersionXy }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ releasePassword
1515
/temp_*
1616
/.nyc_output
1717
.circleci/.pat
18+
test-results*

.mocharc.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ spec: test/**/*.test.*
22
extension: [ts, js]
33
exit: true
44
slow: 10000
5-
timeout: 20000
6-
reporter: spec
5+
timeout: 40000
6+
reporter: mocha-multi-reporters
7+
require: test/hooks.js
8+
reporter-option:
9+
- configFile=mocha-multi-reporters.json

mocha-multi-reporters.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"reporterEnabled": "spec, mocha-junit-reporter, mocha-json-output-reporter",
3+
"mochaJunitReporterReporterOptions": {
4+
"mochaFile": "test-results.xml"
5+
},
6+
"mochaJsonOutputReporterReporterOptions": {
7+
"output": "test-results.json"
8+
}
9+
}

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "NodeJS driver for SuperTokens core",
55
"main": "index.js",
66
"scripts": {
7-
"test": "TEST_MODE=testing npx ts-mocha -p lib/tsconfig.json -n loader=ts-node/esm --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --timeout 500000",
7+
"test": "TEST_MODE=testing npx ts-mocha -p lib/tsconfig.json -n loader=ts-node/esm --node-option no-experimental-fetch -r test/fetch-polyfill.mjs",
88
"test-exports": "./test/testExports.sh",
99
"build-check": "cd lib && npx tsc -p tsconfig.json --noEmit && cd ../test/with-typescript && npm run build",
1010
"build": "cd lib && rm -rf build && npx tsc -p tsconfig.json && cd ../test/with-typescript && npm run build && cd ../.. && npm run post-build",
@@ -137,7 +137,7 @@
137137
"pako": "^2.1.0",
138138
"pkce-challenge": "^3.0.0",
139139
"process": "^0.11.10",
140-
"set-cookie-parser": "^2.6.0",
140+
"set-cookie-parser": "^2.7.1",
141141
"supertokens-js-override": "^0.0.4",
142142
"tldts": "^6.1.48",
143143
"twilio": "^4.19.3"
@@ -173,8 +173,11 @@
173173
"loopback-datasource-juggler": "^4.26.0",
174174
"mocha": "^10.2.0",
175175
"mocha-split-tests": "github:rishabhpoddar/mocha-split-tests",
176+
"mocha-json-output-reporter": "^2.1.0",
177+
"mocha-junit-reporter": "^2.2.1",
178+
"mocha-multi-reporters": "^1.5.1",
176179
"next": "^14.0.4",
177-
"next-test-api-route-handler": "^3.1.10",
180+
"next-test-api-route-handler": "^4.0.16",
178181
"nock": "11.7.0",
179182
"node-fetch": "^3.3.2",
180183
"nyc": "^15.1.0",
@@ -193,4 +196,4 @@
193196
"browser": {
194197
"fs": false
195198
}
196-
}
199+
}

test/auth-modes.test.js

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
*/
1515
const {
1616
printPath,
17-
setupST,
18-
startST,
19-
killAllST,
20-
cleanST,
17+
18+
createCoreApplication,
19+
2120
extractInfoFromResponse,
22-
setKeyValueInConfig,
21+
2322
delay,
2423
} = require("./utils");
2524
const assert = require("assert");
@@ -37,25 +36,19 @@ const exampleJWT =
3736

3837
describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
3938
beforeEach(async function () {
40-
await killAllST();
41-
await setupST();
4239
ProcessState.getInstance().reset();
4340
});
4441

4542
afterEach(function () {
4643
sinon.restore();
4744
});
4845

49-
after(async function () {
50-
await killAllST();
51-
await cleanST();
52-
});
53-
5446
describe("with default getTokenTransferMethod", () => {
5547
describe("createNewSession", () => {
5648
describe("with default getTokenTransferMethod", () => {
5749
it("should default to header based session w/ no auth-mode header", async function () {
58-
const connectionURI = await startST();
50+
const connectionURI = await createCoreApplication();
51+
5952
SuperTokens.init({
6053
supertokens: {
6154
connectionURI,
@@ -79,7 +72,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
7972
});
8073

8174
it("should default to header based session w/ bad auth-mode header", async function () {
82-
const connectionURI = await startST();
75+
const connectionURI = await createCoreApplication();
8376
SuperTokens.init({
8477
supertokens: {
8578
connectionURI,
@@ -103,7 +96,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
10396
});
10497

10598
it("should use headers if auth-mode specifies it", async function () {
106-
const connectionURI = await startST();
99+
const connectionURI = await createCoreApplication();
107100
SuperTokens.init({
108101
supertokens: {
109102
connectionURI,
@@ -127,7 +120,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
127120
});
128121

129122
it("should use cookies if auth-mode specifies it", async function () {
130-
const connectionURI = await startST();
123+
const connectionURI = await createCoreApplication();
131124
SuperTokens.init({
132125
supertokens: {
133126
connectionURI,
@@ -157,7 +150,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
157150

158151
describe("with user provided getTokenTransferMethod", () => {
159152
it("should use headers if getTokenTransferMethod returns any and there is no st-auth-mode header", async function () {
160-
const connectionURI = await startST();
153+
const connectionURI = await createCoreApplication();
161154
SuperTokens.init({
162155
supertokens: {
163156
connectionURI,
@@ -181,7 +174,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
181174
});
182175

183176
it("should use cookies if getTokenTransferMethod returns any and st-auth-mode is set to cookie", async function () {
184-
const connectionURI = await startST();
177+
const connectionURI = await createCoreApplication();
185178
SuperTokens.init({
186179
supertokens: {
187180
connectionURI,
@@ -205,7 +198,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
205198
});
206199

207200
it("should use headers if getTokenTransferMethod returns any and st-auth-mode is set to header", async function () {
208-
const connectionURI = await startST();
201+
const connectionURI = await createCoreApplication();
209202
SuperTokens.init({
210203
supertokens: {
211204
connectionURI,
@@ -229,7 +222,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
229222
});
230223

231224
it("should use headers if getTokenTransferMethod returns header", async function () {
232-
const connectionURI = await startST();
225+
const connectionURI = await createCoreApplication();
233226
SuperTokens.init({
234227
supertokens: {
235228
connectionURI,
@@ -253,7 +246,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
253246
});
254247

255248
it("should use clear cookies (if present) if getTokenTransferMethod returns header", async function () {
256-
const connectionURI = await startST();
249+
const connectionURI = await createCoreApplication();
257250
SuperTokens.init({
258251
supertokens: {
259252
connectionURI,
@@ -293,7 +286,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
293286
});
294287

295288
it("should use cookies if getTokenTransferMethod returns cookie", async function () {
296-
const connectionURI = await startST();
289+
const connectionURI = await createCoreApplication();
297290
SuperTokens.init({
298291
supertokens: {
299292
connectionURI,
@@ -321,7 +314,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
321314
});
322315

323316
it("should clear headers (if present) if getTokenTransferMethod returns cookie", async function () {
324-
const connectionURI = await startST();
317+
const connectionURI = await createCoreApplication();
325318
SuperTokens.init({
326319
supertokens: {
327320
connectionURI,
@@ -393,7 +386,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
393386
for (let i = 0; i < behaviourTable.length; ++i) {
394387
const conf = behaviourTable[i];
395388
it(`should match line ${i + 1} with a valid token`, async () => {
396-
const connectionURI = await startST();
389+
const connectionURI = await createCoreApplication();
397390
SuperTokens.init({
398391
supertokens: {
399392
connectionURI,
@@ -445,7 +438,8 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
445438
});
446439

447440
it(`should match line ${i + 1} with a expired token`, async () => {
448-
const connectionURI = await startST({ coreConfig: { access_token_validity: 2 } });
441+
const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 2 } });
442+
449443
SuperTokens.init({
450444
supertokens: {
451445
connectionURI,
@@ -500,7 +494,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
500494

501495
describe("with access tokens in both headers and cookies", () => {
502496
it("should use the value from headers if getTokenTransferMethod returns any", async () => {
503-
const connectionURI = await startST();
497+
const connectionURI = await createCoreApplication();
504498
SuperTokens.init({
505499
supertokens: {
506500
connectionURI,
@@ -547,7 +541,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
547541
});
548542

549543
it("should use the value from headers if getTokenTransferMethod returns header", async () => {
550-
const connectionURI = await startST();
544+
const connectionURI = await createCoreApplication();
551545
SuperTokens.init({
552546
supertokens: {
553547
connectionURI,
@@ -595,7 +589,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
595589
});
596590

597591
it("should use the value from cookies if getTokenTransferMethod returns cookie", async () => {
598-
const connectionURI = await startST();
592+
const connectionURI = await createCoreApplication();
599593
SuperTokens.init({
600594
supertokens: {
601595
connectionURI,
@@ -644,7 +638,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
644638
});
645639

646640
it("should reject requests with sIdRefreshToken", async () => {
647-
const connectionURI = await startST();
641+
const connectionURI = await createCoreApplication();
648642
SuperTokens.init({
649643
supertokens: {
650644
connectionURI,
@@ -687,7 +681,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
687681

688682
describe("with non ST in Authorize header", () => {
689683
it("should use the value from cookies if present and getTokenTransferMethod returns any", async () => {
690-
const connectionURI = await startST();
684+
const connectionURI = await createCoreApplication();
691685
SuperTokens.init({
692686
supertokens: {
693687
connectionURI,
@@ -730,7 +724,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
730724
});
731725

732726
it("should reject with UNAUTHORISED if getTokenTransferMethod returns header", async () => {
733-
const connectionURI = await startST();
727+
const connectionURI = await createCoreApplication();
734728
SuperTokens.init({
735729
supertokens: {
736730
connectionURI,
@@ -774,7 +768,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
774768
});
775769

776770
it("should reject with UNAUTHORISED if cookies are not present", async () => {
777-
const connectionURI = await startST();
771+
const connectionURI = await createCoreApplication();
778772
SuperTokens.init({
779773
supertokens: {
780774
connectionURI,
@@ -815,7 +809,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
815809

816810
describe("mergeIntoAccessTokenPayload", () => {
817811
it("should update cookies if the session was cookie based", async function () {
818-
const connectionURI = await startST();
812+
const connectionURI = await createCoreApplication();
819813
SuperTokens.init({
820814
supertokens: {
821815
connectionURI,
@@ -852,7 +846,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
852846
});
853847

854848
it("should allow headers if the session was header based", async function () {
855-
const connectionURI = await startST();
849+
const connectionURI = await createCoreApplication();
856850
SuperTokens.init({
857851
supertokens: {
858852
connectionURI,
@@ -910,7 +904,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
910904
for (let i = 0; i < behaviourTable.length; ++i) {
911905
const conf = behaviourTable[i];
912906
it(`should match line ${i + 1} with a valid token`, async () => {
913-
const connectionURI = await startST();
907+
const connectionURI = await createCoreApplication();
914908
SuperTokens.init({
915909
supertokens: {
916910
connectionURI,
@@ -1011,7 +1005,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
10111005
const conf = behaviourTable[i];
10121006

10131007
it(`should match line ${i + 1} with a invalid token`, async () => {
1014-
const connectionURI = await startST();
1008+
const connectionURI = await createCoreApplication();
10151009
SuperTokens.init({
10161010
supertokens: {
10171011
connectionURI,

0 commit comments

Comments
 (0)