Skip to content

Commit 1ca0cd5

Browse files
committed
getting test environments working
1 parent df223f5 commit 1ca0cd5

File tree

15 files changed

+225
-86
lines changed

15 files changed

+225
-86
lines changed

.aegir.cjs

+29
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1+
// import { MockServer } from './test/MockServer'
2+
3+
// let mockServer = new MockServer()
4+
require('ts-node').register({
5+
project: 'tsconfig.json',
6+
})
7+
const { MockServer } = require('./test/MockServer')
8+
19
/** @type {import('aegir').PartialOptions} */
210
module.exports = {
11+
docs: {
12+
publish: true,
13+
entryPoint: './'
14+
},
315
tsRepo: true,
416
build: {
517
config: {
618
platform: 'node'
719
},
820
bundlesizeMax: '44KB'
21+
},
22+
test: {
23+
async before () {
24+
25+
},
26+
async beforeEach () {
27+
28+
// mockServer = new MockServer()
29+
await mockServer.start()
30+
},
31+
async afterEach () {
32+
33+
await mockServer.stop()
34+
},
35+
async after () {
36+
37+
}
938
}
1039
}

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ use asdf
33
export PATH=$(npm bin):${PATH}
44
export MOCK_PINNING_SERVER_PORT=3000
55
export MOCK_PINNING_SERVER_SECRET=secret
6+
export DEBUG=1

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ yarn.lock
99
test/ts-use/tsconfig.tsbuildinfo
1010
test/tsconfig.tsbuildinfo
1111
package-lock.json
12+
*.bak
13+
.swc

fixtures.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
// @ts-check
3-
export async function mochaGlobalSetup () {
3+
// export async function mochaGlobalSetup () {
44

5-
}
5+
// }
66

7-
export async function mochaGlobalTeardown () {
7+
// export async function mochaGlobalTeardown () {
88

9-
}
9+
// }

npm-scripts/fix/gen.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
main() {
4+
# Get all generated files
5+
# local FILES
6+
# FILES=()
7+
local SED_BACKUPS=()
8+
9+
# remove openapi-generator's package and tsconfig json files
10+
for PKG_JSON in generated/*/package.json; do
11+
rm $PKG_JSON
12+
done
13+
for TSC_JSON in generated/*/tsconfig.json; do
14+
rm $TSC_JSON
15+
done
16+
17+
for FILES_LIST in $(find generated/*/.openapi-generator/FILES); do
18+
echo FILES_LIST = $FILES_LIST
19+
for FILE in $(cat $FILES_LIST); do
20+
local DIR=$(dirname $(dirname $FILES_LIST))
21+
local FILE_PATH="${DIR}/${FILE}"
22+
echo "FILE=${FILE_PATH}"
23+
24+
if test -e $FILE_PATH; then
25+
# Replace all occurrances of "&lt;" with "<"
26+
# Replace all occurrances of "&gt;" with ">"
27+
sed -i .bak -e 's/&lt\;/\</g' -e 's/&gt\;/\>/g' $FILE_PATH
28+
SED_BACKUPS+=( $FILE_PATH.bak )
29+
fi
30+
done
31+
done
32+
33+
34+
echo "SED_BACKUPS = ${SED_BACKUPS[@]}"
35+
# test build.. if build succeeds, remove backup file.
36+
37+
}
38+
39+
40+
main $@

package.json

+18-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
"bugs": {
1313
"url": "https://github.com/ipfs-shipyard/js-pinning-service-http-client/issues"
1414
},
15+
"keywords": [
16+
"dweb",
17+
"ipfs",
18+
"pinning service",
19+
"protocol labs",
20+
"web3"
21+
],
1522
"engines": {
1623
"node": ">=16.0.0",
1724
"npm": ">=7.0.0"
@@ -126,14 +133,17 @@
126133
"scripts": {
127134
"dep-check": "aegir dep-check src/**/*.ts test/**/*.ts generated/**/*.ts",
128135
"fix": "run-s fix:*",
129-
"fix:gen": "./npm-scripts/fix/generated-code.sh",
136+
"fix:gen": "./npm-scripts/fix/gen.sh",
130137
"fix:lint": "aegir lint --fix",
131138
"lint": "run-s lint:*",
132139
"lint:main": "aegir lint",
133-
"lint:project": "check-aegir-project",
140+
"lint:ts": "aegir ts -p check -- -p tsconfig.json --suppress 6133@generated 6192@generated --stats",
141+
"lint-TODO:project": "check-aegir-project # currently broken due to corrupting the repoUrl",
134142
"release": "aegir release",
135143
"postinstall": "./npm-scripts/postinstall.sh",
136144
"build": "aegir build -- -p tsconfig.json --suppress 6133@generated 6192@generated --stats",
145+
"build:main": "aegir build -- -p tsconfig.json --suppress 6133@generated 6192@generated --stats",
146+
"build:docs": "aegir ts docs",
137147
"test": "run-p test:*",
138148
"test:electron": "aegir test --target electron-main",
139149
"test:node": "aegir test --target node --cov && npx nyc report",
@@ -150,18 +160,22 @@
150160
},
151161
"devDependencies": {
152162
"@openapitools/openapi-generator-cli": "^2.4.26",
153-
"@types/collections": "^5.1.2",
163+
"@swc/core": "^1.2.144",
164+
"@swc/helpers": "^0.3.3",
154165
"@types/express": "^4.17.13",
155166
"@types/mocha": "^9.1.0",
156167
"@types/node": "^17.0.16",
157168
"@types/node-fetch": "^3.0.3",
169+
"@types/portscanner": "^2.1.1",
158170
"aegir": "^36.1.3",
159171
"check-aegir-project": "^1.0.3",
160-
"collections": "^5.1.13",
161172
"dotenvrc": "^1.0.1",
162173
"mock-ipfs-pinning-service": "^0.4.0",
163174
"npm-run-all": "^4.1.5",
164175
"openapi-typescript": "^5.1.1",
176+
"portscanner": "^2.2.0",
177+
"regenerator-runtime": "^0.13.9",
178+
"ts-node": "^10.5.0",
165179
"tsc-silent": "^1.2.1"
166180
},
167181
"exports": {

test/MockServer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export class MockServer {
7777
token: process.env.MOCK_PINNING_SERVER_SECRET
7878
})
7979

80-
return this._service
80+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
81+
return this._service as Application
8182
}
8283

8384
private async server (port = this.port): Promise<Server> {

test/PinsApi.spec.ts

-74
This file was deleted.

test/browser-tests/.gitkeep

Whitespace-only changes.

test/browser.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable no-console */
2+
3+
import clientTests from './isomorphic-tests/client'
4+
import configurationTests from './isomorphic-tests/configuration'
5+
6+
7+
8+
const setup = async () => {
9+
return await new Promise<void>((resolve, reject) => {
10+
void resolve()
11+
})
12+
}
13+
14+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
15+
describe('browser', async (): Promise<void> => {
16+
console.log(fetch)
17+
await configurationTests(setup)
18+
await clientTests(setup)
19+
})

test/isomorphic-tests/client.ts

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* eslint-env browser, node, mocha */
2+
3+
import { expect } from 'aegir/utils/chai'
4+
import { Configuration, PinsApi } from '../../src'
5+
6+
export default async (setup: () => Promise<unknown>) => {
7+
describe('Client', () => {
8+
const Config = new Configuration({
9+
basePath: `http://127.0.0.1:${process.env.MOCK_PINNING_SERVER_PORT ?? '3000'}`,
10+
fetchApi: fetch as GlobalFetch['fetch'],
11+
accessToken: process.env.MOCK_PINNING_SERVER_SECRET
12+
})
13+
14+
it('Can be instantiated', () => {
15+
expect(() => new PinsApi(Config)).not.to.throw()
16+
})
17+
18+
// describe.skip('Operations', () => {
19+
// let mockServer: MockServer
20+
// beforeEach(async () => {
21+
// mockServer = new MockServer()
22+
// await mockServer.start()
23+
// })
24+
25+
// afterEach(async () => {
26+
// await mockServer.stop()
27+
// })
28+
29+
// it('GET: Can get failed Pins', async () => {
30+
// const Client = new PinsApi(getClientConfigForMockServer(mockServer))
31+
// const response = await Client.pinsGet({ limit: 1, status: new Set([Status.Failed]) })
32+
// expect(response).to.deep.eq({ count: 0, results: new Set() })
33+
// })
34+
35+
// it('GET: Can add a Pin successfully', async () => {
36+
// const Client = new PinsApi(getClientConfigForMockServer(mockServer))
37+
// const pin: Pin = {
38+
// cid: 'abc123',
39+
// name: 'pinned-test1'
40+
// }
41+
// const response = await Client.pinsPost({ pin })
42+
// expect(response).to.deep.includes({ status: Status.Pinned })
43+
// expect(response.pin).to.deep.include({ ...pin })
44+
// })
45+
46+
// it('POST: Can handle a failed pinning', async () => {
47+
// const Client = new PinsApi(getClientConfigForMockServer(mockServer))
48+
// const pin: Pin = {
49+
// cid: 'abc123',
50+
// name: 'failed-test2'
51+
// }
52+
// const response = await Client.pinsPost({ pin })
53+
// expect(response).to.deep.includes({ status: Status.Failed })
54+
// expect(response.pin).to.deep.include({ ...pin })
55+
// })
56+
// })
57+
})
58+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-env browser, node, mocha */
2+
3+
import { expect } from 'aegir/utils/chai'
4+
import { Configuration, ConfigurationParameters } from '../../src'
5+
6+
export default async (setup: () => Promise<unknown>) => {
7+
describe('Configuration', () => {
8+
it('Can be instantiated', () => {
9+
const configuration: ConfigurationParameters = {}
10+
expect(() => new Configuration(configuration)).not.to.throw()
11+
})
12+
})
13+
}

test/node-tests/.gitkeep

Whitespace-only changes.

test/node.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable no-console */
2+
3+
import clientTests from './isomorphic-tests/client'
4+
import configurationTests from './isomorphic-tests/configuration'
5+
import fetch from 'node-fetch'
6+
7+
const setup = async () => {
8+
return await new Promise<void>((resolve, reject) => {
9+
void resolve()
10+
})
11+
}
12+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
13+
describe('node', async (): Promise<void> => {
14+
console.log(fetch)
15+
await configurationTests(setup)
16+
await clientTests(setup)
17+
})
18+
19+
// const getClientConfigForMockServer = (mockServer: MockServer) => new Configuration({
20+
// basePath: mockServer.basePath,
21+
// fetchApi: fetch as GlobalFetch['fetch'],
22+
// accessToken: process.env.MOCK_PINNING_SERVER_SECRET
23+
// })

tsconfig.json

+16-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,21 @@
1212
"include": [
1313
"src",
1414
"generated",
15-
"test/*.ts",
15+
"test/**/*.ts",
1616
"generated",
17-
"types/*.d.ts"
18-
]
17+
"types/**/*.d.ts"
18+
],
19+
"ts-node": {
20+
"transpileOnly": true,
21+
"files": true,
22+
"emit": false,
23+
"compiler": "typescript",
24+
"compilerHost": false,
25+
"compilerOptions": {
26+
"module": "CommonJS"
27+
},
28+
"preferTsExts": true,
29+
"pretty": true,
30+
"swc": true
31+
}
1932
}

0 commit comments

Comments
 (0)