From 8bf1c928b07d41b9239b605191cdac7b00262d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Fri, 8 Mar 2024 11:26:59 +0100 Subject: [PATCH] test(sanity): use dev aliases in the validation test's worker threads (#5927) This allows us to run the test suite directly from source, without first having to build --- dev/aliases.cjs | 1 + .../cli/threads/__tests__/validateDocuments.test.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/dev/aliases.cjs b/dev/aliases.cjs index cb1c599c248..8e2eef55163 100644 --- a/dev/aliases.cjs +++ b/dev/aliases.cjs @@ -18,6 +18,7 @@ const devAliases = { // because they will be escaped by the jest config '@sanity/block-tools': './packages/@sanity/block-tools/src', '@sanity/diff': './packages/@sanity/diff/src', + '@sanity/cli': './packages/@sanity/cli/src', '@sanity/mutator': './packages/@sanity/mutator/src', '@sanity/portable-text-editor': './packages/@sanity/portable-text-editor/src', '@sanity/schema': './packages/@sanity/schema/src/_exports', diff --git a/packages/sanity/src/_internal/cli/threads/__tests__/validateDocuments.test.ts b/packages/sanity/src/_internal/cli/threads/__tests__/validateDocuments.test.ts index 76e571866ed..18a6edc83e1 100644 --- a/packages/sanity/src/_internal/cli/threads/__tests__/validateDocuments.test.ts +++ b/packages/sanity/src/_internal/cli/threads/__tests__/validateDocuments.test.ts @@ -2,8 +2,10 @@ import {afterAll, beforeAll, describe, expect, it, jest} from '@jest/globals' import {type SanityDocument, type SanityProject} from '@sanity/client' import {evaluate, parse} from 'groq-js' import {createServer, type Server} from 'http' +import path from 'path' import {Worker} from 'worker_threads' +import {getAliases} from '../../server/aliases' import {createReceiver, type WorkerChannelReceiver} from '../../util/workerChannels' import {type ValidateDocumentsWorkerData, type ValidationWorkerChannel} from '../validateDocuments' @@ -198,8 +200,11 @@ describe('validateDocuments', () => { const worker = new Worker( ` + const moduleAlias = require('module-alias') const { register } = require('esbuild-register/dist/node') + moduleAlias.addAliases(${JSON.stringify(getAliases({monorepo: {path: path.resolve(__dirname, '../../../../../../..')}}))}) + const { unregister } = register({ target: 'node18', format: 'cjs',