Skip to content

Commit

Permalink
move stream-metadata to vitest (#1581)
Browse files Browse the repository at this point in the history
stacked on top of #1576

I'm breaking #1462 into small PRs

Moving the stream-metadata package from jest to vitest.

Some tests wasn't enabled: the test suite name wasn't being matched with
the name pattern of test:integration script
Those tests were outdated, did a few changes to match the expected
current behavior.
  • Loading branch information
miguel-nascimento authored Nov 21, 2024
1 parent 42cb997 commit f4ccc09
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 127 deletions.
29 changes: 10 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,20 @@
"console": "integratedTerminal",
},
{
"name": "Jest: current file in 'packages/stream-metadata (local_multi_ne)'",
"name": "Vitest: current file in 'packages/stream-metadata/' (local_multi_ne)",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/packages/stream-metadata",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"runtimeArgs": [
"--experimental-vm-modules"
],
"args": [
"${relativeFile}",
"--config",
"${workspaceFolder}/packages/stream-metadata/jest.config.ts",
"--runInBand",
"--no-cache",
"--forceExit"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"env": {
"NODE_TLS_REJECT_UNAUTHORIZED": "0", "NODE_EXTRA_CA_CERTS":"~/river-ca-cert.pem",
"RIVER_ENV": "local_multi_ne",
"PORT": "3003",
}
}
},
"program": "${workspaceFolder}/node_modules/vitest/vitest.mjs",
"cwd": "${workspaceFolder}/packages/stream-metadata",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"smartStep": true,
"args": ["run", "${fileBasename}", "--config", "vitest.config.ts"],
"console": "integratedTerminal",
},
]
}
6 changes: 3 additions & 3 deletions packages/stream-metadata/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.config.ts
jest.setup.ts
vitest.config.ts
vitest.setup.ts
dist/
node_modules/
node_modules/
7 changes: 1 addition & 6 deletions packages/stream-metadata/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended",
"plugin:jest/recommended"
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand All @@ -30,10 +29,6 @@
"project": "./tsconfig.test.json"
},
"rules": {
"jest/no-standalone-expect": "off",
"jest/expect-expect": "off",
"jest/no-conditional-expect": "off",
"jest/no-disabled-tests": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unsafe-argument": "off",
Expand Down
32 changes: 0 additions & 32 deletions packages/stream-metadata/jest.config.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/stream-metadata/jest.setup.ts

This file was deleted.

13 changes: 5 additions & 8 deletions packages/stream-metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"prettier": "prettier --config ../prettier-config/config.js --ignore-path .prettierignore .",
"run-build": "yarn build && node ./dist/node_esbuild.cjs",
"start": "node ./dist/node_esbuild.cjs",
"test": "NODE_TLS_REJECT_UNAUTHORIZED=0 node --experimental-vm-modules $(yarn bin jest) --forceExit",
"test:integration": "yarn test --testNamePattern='integration/stream-metadata'",
"test": "vitest run",
"test:integration": "vitest run --testNamePattern integration/stream-metadata",
"test:watch": "vitest --watch",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand Down Expand Up @@ -51,7 +52,6 @@
"@river-build/encryption": "workspace:^",
"@river-build/eslint-config": "workspace:^",
"@river-build/prettier-config": "workspace:^",
"@types/jest": "^29.5.3",
"@types/node": "^20.5.0",
"@types/uuid": "^10.0.0",
"@typescript-eslint/parser": "^7.14.1",
Expand All @@ -62,11 +62,8 @@
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-prettier": "^4.2.1",
"fake-indexeddb": "^4.0.1",
"jest": "^29.6.2",
"jest-transform-stub": "^2.0.0",
"prettier": "^2.8.8",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"vitest": "^2.1.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const log = dlog('stream-metadata:test:spaceMemberMetadata', {
defaultEnabled: true,
})

describe('integration/space/:spaceAddress/token/:tokenId', () => {
describe('integration/stream-metadata/:spaceAddress/token/:tokenId', () => {
const baseURL = getTestServerUrl()
log('baseURL', baseURL)

Expand Down Expand Up @@ -69,7 +69,7 @@ describe('integration/space/:spaceAddress/token/:tokenId', () => {
expect(response.headers['content-type']).toContain('application/json')
expect(name).toEqual(`${spaceMetadata.name} - Member`)
expect(description).toEqual(`Member of ${spaceMetadata.name}`)
expect(image).toBe(`${baseURL}/space/${spaceAddress}/image`)
expect(image).toContain(`${baseURL}/space/${spaceAddress}/image`)

const renewalPrice = attributes.find((attr) => attr.trait_type === 'Renewal Price')
expect(renewalPrice).toBeDefined()
Expand All @@ -92,7 +92,7 @@ describe('integration/space/:spaceAddress/token/:tokenId', () => {
await runTest(spaceAddress, 0, metadata)
})

it('should return 404 /space/:spaceAddress/token/42069', async () => {
it('should return 200 - any token id is valid for a space', async () => {
const metadata = {
name: 'Alice Space',
uri: baseURL,
Expand All @@ -103,6 +103,6 @@ describe('integration/space/:spaceAddress/token/:tokenId', () => {
const response = await axios.get<SpaceMemberMetadataResponse>(
`${baseURL}/space/${spaceAddress}/token/42069`,
)
expect(response.status).toBe(404)
expect(response.status).toBe(200)
})
})
39 changes: 12 additions & 27 deletions packages/stream-metadata/tests/integration/spaceMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
makeTestClient,
SpaceMetadataParams,
} from '../testUtils'
import { config } from '../../src/environment'
import { spaceMetadataBaseUrl, SpaceMetadataResponse } from '../../src/routes/spaceMetadata'
import { spaceDapp } from '../../src/contract-utils'

Expand All @@ -21,7 +20,7 @@ const log = dlog('stream-metadata:test:spaceMetadata', {
defaultEnabled: true,
})

describe('integration/space/:spaceAddress', () => {
describe('integration/stream-metadata/space/:spaceAddress', () => {
const baseURL = getTestServerUrl()
log('baseURL', baseURL)

Expand Down Expand Up @@ -138,7 +137,7 @@ describe('integration/space/:spaceAddress', () => {
imageData,
)

await bobsClient.setSpaceImage(spaceStreamId, chunkedMedia)
const { eventId } = await bobsClient.setSpaceImage(spaceStreamId, chunkedMedia)

/*
* 4. fetch the space metadata from the stream-metadata server.
Expand All @@ -159,29 +158,15 @@ describe('integration/space/:spaceAddress', () => {
}
}

/*
* 5. verify the response.
*/
if (spaceUri.trim() === '' || spaceUri.toLowerCase() === spaceMetadataBaseUrl) {
// 200 response case
const { name, description, image: imageUrl } = response.data
expect(response.status).toBe(200)
expect(response.headers['content-type']).toContain('application/json')
expect(name).toEqual(expectedMetadata.name)
const expectedDescription = `${expectedMetadata.shortDescription}<br><br>${expectedMetadata.longDescription}`
expect(description).toEqual(expectedDescription)

let expectedImageUrl = spaceUri
if (spaceUri.trim() === '' || spaceUri === config.streamMetadataBaseUrl) {
expectedImageUrl = `${spaceMetadataBaseUrl}/${spaceAddress}/image`
}
expect(imageUrl.toLowerCase()).toEqual(expectedImageUrl.toLowerCase())
} else {
// 302 redirect case
expect(response.status).toBe(302)
expect(response.headers['location']).toBeDefined()
expect(response.headers['location']).toEqual(spaceUri.toLowerCase())
}
const { name, description, image: imageUrl } = response.data
expect(response.status).toBe(200)
expect(response.headers['content-type']).toContain('application/json')
expect(name).toEqual(expectedMetadata.name)
const expectedDescription = `${expectedMetadata.shortDescription}<br><br>${expectedMetadata.longDescription}`
expect(description).toEqual(expectedDescription)

const expectedImageUrl = `${spaceMetadataBaseUrl}/${spaceAddress}/image/${eventId}`
expect(imageUrl.toLowerCase()).toEqual(expectedImageUrl.toLowerCase())
}

it('should return 404 /space', async () => {
Expand Down Expand Up @@ -238,7 +223,7 @@ describe('integration/space/:spaceAddress', () => {
await runSpaceImageTest(' ')
})

it('should return status 302 with spaceImage when uri is https://example.com', async () => {
it('should return status 200 even if spaceUri is https://example.com', async () => {
await runSpaceImageTest('https://example.com')
})
})
6 changes: 2 additions & 4 deletions packages/stream-metadata/tests/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ export function makeUniqueSpaceStreamId(): string {

export function getTestServerUrl() {
// use the .env.test config to derive the baseURL of the server under test
const { host, port, riverEnv } = config
const protocol = riverEnv.startsWith('local') ? 'http' : 'https'
const baseURL = `${protocol}://${host}:${port}`
return baseURL
const { streamMetadataBaseUrl } = config
return streamMetadataBaseUrl
}

export async function getAnyNodeUrlFromRiverRegistry() {
Expand Down
3 changes: 2 additions & 1 deletion packages/stream-metadata/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"strict": true,
"outDir": "./dist",
"rootDir": "./src",
"sourceMap": true
"sourceMap": true,
"types": ["vitest/globals"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist", "tests"]
Expand Down
12 changes: 12 additions & 0 deletions packages/stream-metadata/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig, mergeConfig } from 'vitest/config'
import { rootConfig } from '../../vitest.config.mjs'

export default mergeConfig(
rootConfig,
defineConfig({
test: {
include: ['tests/**/*.test.ts'],
setupFiles: './vitest.setup.ts',
},
}),
)
5 changes: 5 additions & 0 deletions packages/stream-metadata/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import dotenv from 'dotenv'
import { resolve } from 'path'
import 'fake-indexeddb/auto'

dotenv.config({ path: resolve(__dirname, '.env.test') })
13 changes: 1 addition & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6406,7 +6406,6 @@ __metadata:
"@river-build/proto": "workspace:^"
"@river-build/sdk": "workspace:^"
"@river-build/web3": "workspace:^"
"@types/jest": ^29.5.3
"@types/node": ^20.5.0
"@types/uuid": ^10.0.0
"@typescript-eslint/parser": ^7.14.1
Expand All @@ -6422,17 +6421,14 @@ __metadata:
ethers: ^5.7.2
fake-indexeddb: ^4.0.1
fastify: ^4.28.1
jest: ^29.6.2
jest-transform-stub: ^2.0.0
lru-cache: ^11.0.1
magic-bytes.js: ^1.10.0
pino: ^8.17.1
pino-pretty: ^10.2.3
prettier: ^2.8.8
ts-jest: ^29.1.1
ts-node: ^10.9.1
typescript: ^5.1.6
uuid: ^8.3.2
vitest: ^2.1.5
zod: ^3.21.4
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -18686,13 +18682,6 @@ __metadata:
languageName: node
linkType: hard

"jest-transform-stub@npm:^2.0.0":
version: 2.0.0
resolution: "jest-transform-stub@npm:2.0.0"
checksum: c46134257e5fb047f5952e4a4a1339925dd009da15aa8d3310ba1d3e4d22266ed6c675cd18e58c9d5ca2246718d6cc8ff00ea6a4b6f3b2a6b285b6426f6ae8fe
languageName: node
linkType: hard

"jest-util@npm:>=27, jest-util@npm:^29.0.0, jest-util@npm:^29.6.2, jest-util@npm:^29.7.0":
version: 29.7.0
resolution: "jest-util@npm:29.7.0"
Expand Down

0 comments on commit f4ccc09

Please sign in to comment.