diff --git a/packages/stream-metadata/.eslintignore b/packages/stream-metadata/.eslintignore index 5e0646af0..16b202e06 100644 --- a/packages/stream-metadata/.eslintignore +++ b/packages/stream-metadata/.eslintignore @@ -1,4 +1,4 @@ -jest.config.ts -jest.setup.ts +vitest.config.ts +vitest.setup.ts dist/ -node_modules/ +node_modules/ \ No newline at end of file diff --git a/packages/stream-metadata/jest.config.ts b/packages/stream-metadata/jest.config.ts deleted file mode 100644 index 0958e51ce..000000000 --- a/packages/stream-metadata/jest.config.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { resolve } from 'path' -import type { Config } from '@jest/types' - -const config: Config.InitialOptions = { - preset: 'ts-jest/presets/default-esm', - extensionsToTreatAsEsm: ['.ts'], - modulePathIgnorePatterns: ['/dist/'], - moduleNameMapper: { - '^(\\.{1,2}/.*)\\.js$': '$1', - '@matrix-org/olm/olm.wasm': resolve(__dirname, './tests/__mocks__/mock-wasm-file.js'), - }, - setupFilesAfterEnv: [resolve(__dirname, './jest.setup.ts')], - setupFiles: ['fake-indexeddb/auto'], - testEnvironment: 'node', - testPathIgnorePatterns: ['/dist/', '/node_modules/'], - testTimeout: 30_000, - transform: { - '^.+\\.ts$': [ - 'ts-jest', - { - useESM: true, - tsconfig: './tsconfig.test.json', - }, - ], - '^.+\\.wasm$': 'jest-transform-stub', - }, - transformIgnorePatterns: ['/node_modules/(?!@river-build)'], - verbose: true, - testMatch: ['**/?(*.)+(test).ts'], -} - -export default config diff --git a/packages/stream-metadata/jest.setup.ts b/packages/stream-metadata/jest.setup.ts deleted file mode 100644 index bd2e1852b..000000000 --- a/packages/stream-metadata/jest.setup.ts +++ /dev/null @@ -1,11 +0,0 @@ -import dotenv from 'dotenv' -import { resolve } from 'path' -import { fileURLToPath } from 'url' -import { dirname } from 'path' - -// ES module equivalent of __dirname -const __filename = fileURLToPath(import.meta.url) -const __dirname = dirname(__filename) - -// Load .env.test environment variables -dotenv.config({ path: resolve(__dirname, '.env.test') }) diff --git a/packages/stream-metadata/package.json b/packages/stream-metadata/package.json index 30ec190cd..bb00ed055 100644 --- a/packages/stream-metadata/package.json +++ b/packages/stream-metadata/package.json @@ -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", @@ -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", @@ -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" } } diff --git a/packages/stream-metadata/tests/integration/spaceMemberMetadata.test.ts b/packages/stream-metadata/tests/integration/spaceMemberMetadata.test.ts index 58d015b24..8ad191b49 100644 --- a/packages/stream-metadata/tests/integration/spaceMemberMetadata.test.ts +++ b/packages/stream-metadata/tests/integration/spaceMemberMetadata.test.ts @@ -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) @@ -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() @@ -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, @@ -103,6 +103,6 @@ describe('integration/space/:spaceAddress/token/:tokenId', () => { const response = await axios.get( `${baseURL}/space/${spaceAddress}/token/42069`, ) - expect(response.status).toBe(404) + expect(response.status).toBe(200) }) }) diff --git a/packages/stream-metadata/tests/integration/spaceMetadata.test.ts b/packages/stream-metadata/tests/integration/spaceMetadata.test.ts index b855c439e..979068f08 100644 --- a/packages/stream-metadata/tests/integration/spaceMetadata.test.ts +++ b/packages/stream-metadata/tests/integration/spaceMetadata.test.ts @@ -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' @@ -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) @@ -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. @@ -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}

${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}

${expectedMetadata.longDescription}` + expect(description).toEqual(expectedDescription) + + const expectedImageUrl = `${spaceMetadataBaseUrl}/${spaceAddress}/image/${eventId}` + expect(imageUrl.toLowerCase()).toEqual(expectedImageUrl.toLowerCase()) } it('should return 404 /space', async () => { @@ -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') }) }) diff --git a/packages/stream-metadata/tests/testUtils.ts b/packages/stream-metadata/tests/testUtils.ts index 0c90da36c..acb57fa8f 100644 --- a/packages/stream-metadata/tests/testUtils.ts +++ b/packages/stream-metadata/tests/testUtils.ts @@ -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() { diff --git a/packages/stream-metadata/vitest.config.ts b/packages/stream-metadata/vitest.config.ts new file mode 100644 index 000000000..0e01fa602 --- /dev/null +++ b/packages/stream-metadata/vitest.config.ts @@ -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', + }, + }), +) diff --git a/packages/stream-metadata/vitest.setup.ts b/packages/stream-metadata/vitest.setup.ts new file mode 100644 index 000000000..852ac04ec --- /dev/null +++ b/packages/stream-metadata/vitest.setup.ts @@ -0,0 +1,5 @@ +import dotenv from 'dotenv' +import { resolve } from 'path' +import 'fake-indexeddb/auto' + +dotenv.config({ path: resolve(__dirname, '.env.test') }) diff --git a/yarn.lock b/yarn.lock index 47f76d318..10d357cd1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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 @@ -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"