Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream-metadata: move to vitest #1468

Open
wants to merge 1 commit into
base: miguel/move-to-vitest-rebased
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
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 @@ -20,8 +20,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"
},
"dependencies": {
"@aws-sdk/client-cloudfront": "^3.645.0",
Expand Down Expand Up @@ -50,7 +51,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 @@ -61,11 +61,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.4"
}
}
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
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 @@ -5110,7 +5110,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 @@ -5126,16 +5125,13 @@ __metadata:
ethers: ^5.7.2
fake-indexeddb: ^4.0.1
fastify: ^4.28.1
jest: ^29.6.2
jest-transform-stub: ^2.0.0
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.4
zod: ^3.21.4
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -15023,13 +15019,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
Loading