From 3969004e54cdd3538d1179a83081d0c1643f6f61 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sat, 27 Apr 2024 19:38:12 +0200 Subject: [PATCH] test: picjs v0.8.1 (#508) * test: picjs v0.8.0 Signed-off-by: David Dal Busco * build: picjs beta Signed-off-by: David Dal Busco * build: pic v0.8.1 Signed-off-by: David Dal Busco --------- Signed-off-by: David Dal Busco --- package-lock.json | 14 +++++++------- package.json | 2 +- src/tests/satellite.auth.spec.ts | 4 ++-- src/tests/satellite.custom-domains.spec.ts | 4 ++-- src/tests/satellite.datastore.spec.ts | 4 ++-- src/tests/satellite.playground.spec.ts | 4 ++-- src/tests/satellite.spec.ts | 4 ++-- src/tests/satellite.storage.spec.ts | 4 ++-- src/tests/satellite.upgrade.spec.ts | 8 ++++---- src/tests/types.d.ts | 5 +++++ vitest.config.ts | 1 + vitest.setup.ts | 15 +++++++++++++++ 12 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 src/tests/types.d.ts create mode 100644 vitest.setup.ts diff --git a/package-lock.json b/package-lock.json index ea9994a6f..228b03386 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "@dfinity/identity-secp256k1": "^1.2.0", "@dfinity/ledger-icrc": "^2.2.1", "@esbuild-plugins/node-modules-polyfill": "^0.2.2", - "@hadronous/pic": "^0.7.0", + "@hadronous/pic": "^0.8.1", "@ltd/j-toml": "^1.38.0", "@rollup/plugin-inject": "^5.0.5", "@sveltejs/adapter-static": "^3.0.1", @@ -640,9 +640,9 @@ } }, "node_modules/@hadronous/pic": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@hadronous/pic/-/pic-0.7.0.tgz", - "integrity": "sha512-539btzwvSF74RTUQHGfOCoUiRyeV8nlZHnJMFlJC8eWPJ4wJrs/O6od2dvlvQquTJNHmHKARe1E4hnfW5oiBhw==", + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@hadronous/pic/-/pic-0.8.1.tgz", + "integrity": "sha512-f7udej5rsmiqQ4Yq8P8+mOqOQe5boVk8UhYAyZcRHvcxChC9x2jKeEYjdM3+w2vmbmCp9a/Ze/iHxFbIK8Jvrw==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -5595,9 +5595,9 @@ "dev": true }, "@hadronous/pic": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@hadronous/pic/-/pic-0.7.0.tgz", - "integrity": "sha512-539btzwvSF74RTUQHGfOCoUiRyeV8nlZHnJMFlJC8eWPJ4wJrs/O6od2dvlvQquTJNHmHKARe1E4hnfW5oiBhw==", + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@hadronous/pic/-/pic-0.8.1.tgz", + "integrity": "sha512-f7udej5rsmiqQ4Yq8P8+mOqOQe5boVk8UhYAyZcRHvcxChC9x2jKeEYjdM3+w2vmbmCp9a/Ze/iHxFbIK8Jvrw==", "dev": true, "requires": { "bip39": "^3.1.0" diff --git a/package.json b/package.json index 93e0527ee..8fa16bcb0 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@dfinity/identity-secp256k1": "^1.2.0", "@dfinity/ledger-icrc": "^2.2.1", "@esbuild-plugins/node-modules-polyfill": "^0.2.2", - "@hadronous/pic": "^0.7.0", + "@hadronous/pic": "^0.8.1", "@ltd/j-toml": "^1.38.0", "@rollup/plugin-inject": "^5.0.5", "@sveltejs/adapter-static": "^3.0.1", diff --git a/src/tests/satellite.auth.spec.ts b/src/tests/satellite.auth.spec.ts index 954cd1ed1..f40c258f9 100644 --- a/src/tests/satellite.auth.spec.ts +++ b/src/tests/satellite.auth.spec.ts @@ -8,7 +8,7 @@ import { Ed25519KeyIdentity } from '@dfinity/identity'; import { toNullable } from '@dfinity/utils'; import { PocketIc, type Actor } from '@hadronous/pic'; import { toArray } from '@junobuild/utils'; -import { afterAll, beforeAll, describe, expect } from 'vitest'; +import {afterAll, beforeAll, describe, expect, inject} from 'vitest'; import { ADMIN_ERROR_MSG } from './constants/satellite-tests.constants'; import { WASM_PATH, satelliteInitArgs } from './utils/satellite-tests.utils'; @@ -19,7 +19,7 @@ describe('Satellite authentication', () => { const controller = Ed25519KeyIdentity.generate(); beforeAll(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const { actor: c } = await pic.setupCanister({ idlFactory: idlFactorSatellite, diff --git a/src/tests/satellite.custom-domains.spec.ts b/src/tests/satellite.custom-domains.spec.ts index 9c77c22cb..5d8bd53ef 100644 --- a/src/tests/satellite.custom-domains.spec.ts +++ b/src/tests/satellite.custom-domains.spec.ts @@ -4,7 +4,7 @@ import { AnonymousIdentity } from '@dfinity/agent'; import { Ed25519KeyIdentity } from '@dfinity/identity'; import { toNullable } from '@dfinity/utils'; import { PocketIc, type Actor } from '@hadronous/pic'; -import { afterAll, beforeAll, describe, expect } from 'vitest'; +import {afterAll, beforeAll, describe, expect, inject} from 'vitest'; import { ADMIN_ERROR_MSG } from './constants/satellite-tests.constants'; import { WASM_PATH, satelliteInitArgs } from './utils/satellite-tests.utils'; @@ -15,7 +15,7 @@ describe('Satellite custom domains', () => { const controller = Ed25519KeyIdentity.generate(); beforeAll(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const { actor: c } = await pic.setupCanister({ idlFactory: idlFactorSatellite, diff --git a/src/tests/satellite.datastore.spec.ts b/src/tests/satellite.datastore.spec.ts index dda09465a..367cb2e04 100644 --- a/src/tests/satellite.datastore.spec.ts +++ b/src/tests/satellite.datastore.spec.ts @@ -5,7 +5,7 @@ import { fromNullable, toNullable } from '@dfinity/utils'; import { PocketIc, type Actor } from '@hadronous/pic'; import { toArray } from '@junobuild/utils'; import { nanoid } from 'nanoid'; -import { afterAll, beforeAll, describe, expect } from 'vitest'; +import {afterAll, beforeAll, describe, expect, inject} from 'vitest'; import { WASM_PATH, satelliteInitArgs } from './utils/satellite-tests.utils'; describe.each([{ memory: { Heap: null } }, { memory: { Stable: null } }])( @@ -19,7 +19,7 @@ describe.each([{ memory: { Heap: null } }, { memory: { Stable: null } }])( const TEST_COLLECTION = 'test'; beforeAll(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const { actor: c } = await pic.setupCanister({ idlFactory: idlFactorSatellite, diff --git a/src/tests/satellite.playground.spec.ts b/src/tests/satellite.playground.spec.ts index 130431532..79a005a82 100644 --- a/src/tests/satellite.playground.spec.ts +++ b/src/tests/satellite.playground.spec.ts @@ -4,7 +4,7 @@ import { Ed25519KeyIdentity } from '@dfinity/identity'; import { toNullable } from '@dfinity/utils'; import { PocketIc, type Actor } from '@hadronous/pic'; import { toArray } from '@junobuild/utils'; -import { afterAll, beforeAll, beforeEach, describe } from 'vitest'; +import {afterAll, beforeAll, beforeEach, describe, inject} from 'vitest'; import { WASM_PATH, satelliteInitArgs } from './utils/satellite-tests.utils'; describe.skip('Satellite playground (kind of)', () => { @@ -14,7 +14,7 @@ describe.skip('Satellite playground (kind of)', () => { const controller = Ed25519KeyIdentity.generate(); beforeAll(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const { actor: c } = await pic.setupCanister({ idlFactory: idlFactorSatellite, diff --git a/src/tests/satellite.spec.ts b/src/tests/satellite.spec.ts index 5e5e27b11..74e63a941 100644 --- a/src/tests/satellite.spec.ts +++ b/src/tests/satellite.spec.ts @@ -6,7 +6,7 @@ import { PocketIc, type Actor } from '@hadronous/pic'; import { parse } from '@ltd/j-toml'; import { readFileSync } from 'node:fs'; import { join } from 'node:path'; -import { afterAll, beforeAll, describe, expect } from 'vitest'; +import {afterAll, beforeAll, describe, expect, inject} from 'vitest'; import { ADMIN_ERROR_MSG, CONTROLLER_ERROR_MSG } from './constants/satellite-tests.constants'; import { WASM_PATH, satelliteInitArgs } from './utils/satellite-tests.utils'; @@ -17,7 +17,7 @@ describe('Satellite', () => { const controller = Ed25519KeyIdentity.generate(); beforeAll(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const { actor: c } = await pic.setupCanister({ idlFactory: idlFactorSatellite, diff --git a/src/tests/satellite.storage.spec.ts b/src/tests/satellite.storage.spec.ts index 3e88a0ff0..7bc6be2f5 100644 --- a/src/tests/satellite.storage.spec.ts +++ b/src/tests/satellite.storage.spec.ts @@ -8,7 +8,7 @@ import { AnonymousIdentity } from '@dfinity/agent'; import { Ed25519KeyIdentity } from '@dfinity/identity'; import { arrayBufferToUint8Array, fromNullable, toNullable } from '@dfinity/utils'; import { PocketIc, type Actor } from '@hadronous/pic'; -import { afterAll, beforeAll, beforeEach, describe, expect } from 'vitest'; +import {afterAll, beforeAll, beforeEach, describe, expect, inject} from 'vitest'; import { ADMIN_ERROR_MSG, CONTROLLER_ERROR_MSG } from './constants/satellite-tests.constants'; import { WASM_PATH, satelliteInitArgs } from './utils/satellite-tests.utils'; @@ -19,7 +19,7 @@ describe('Satellite storage', () => { const controller = Ed25519KeyIdentity.generate(); beforeAll(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const { actor: c } = await pic.setupCanister({ idlFactory: idlFactorSatellite, diff --git a/src/tests/satellite.upgrade.spec.ts b/src/tests/satellite.upgrade.spec.ts index ef374d1ee..56cdb9edd 100644 --- a/src/tests/satellite.upgrade.spec.ts +++ b/src/tests/satellite.upgrade.spec.ts @@ -6,7 +6,7 @@ import type { Principal } from '@dfinity/principal'; import { toNullable } from '@dfinity/utils'; import { PocketIc, type Actor } from '@hadronous/pic'; import { toArray } from '@junobuild/utils'; -import { afterEach, beforeEach, describe, expect } from 'vitest'; +import {afterEach, beforeEach, describe, expect, inject} from 'vitest'; import { WASM_PATH, downloadSatellite, satelliteInitArgs } from './utils/satellite-tests.utils'; describe('satellite upgrade', () => { @@ -93,7 +93,7 @@ describe('satellite upgrade', () => { describe('v0.0.15 -> v0.0.16', async () => { beforeEach(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const destination = await downloadSatellite('0.0.15'); @@ -155,7 +155,7 @@ describe('satellite upgrade', () => { describe('v0.0.11 -> v0.0.16', async () => { beforeEach(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const destination = await downloadSatellite('0.0.11'); @@ -206,7 +206,7 @@ describe('satellite upgrade', () => { describe('v0.0.16 -> v0.0.16', async () => { beforeEach(async () => { - pic = await PocketIc.create(); + pic = await PocketIc.create(inject('PIC_URL')); const { actor: c, canisterId: cId } = await pic.setupCanister({ idlFactory: idlFactorSatellite, diff --git a/src/tests/types.d.ts b/src/tests/types.d.ts new file mode 100644 index 000000000..e8aa36d22 --- /dev/null +++ b/src/tests/types.d.ts @@ -0,0 +1,5 @@ +export declare module 'vitest' { + export interface ProvidedContext { + PIC_URL: string; + } +} \ No newline at end of file diff --git a/vitest.config.ts b/vitest.config.ts index 73e754026..0cb1d36f0 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -3,6 +3,7 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { + globalSetup: './vitest.setup.ts', globals: true, watch: false, silent: false, diff --git a/vitest.setup.ts b/vitest.setup.ts new file mode 100644 index 000000000..1c8835b62 --- /dev/null +++ b/vitest.setup.ts @@ -0,0 +1,15 @@ +import type { GlobalSetupContext } from 'vitest/node'; +import { PocketIcServer } from '@hadronous/pic'; + +let pic: PocketIcServer | undefined; + +export async function setup(ctx: GlobalSetupContext): Promise { + pic = await PocketIcServer.start(); + const url = pic.getUrl(); + + ctx.provide('PIC_URL', url); +} + +export async function teardown(): Promise { + await pic?.stop(); +} \ No newline at end of file