Skip to content
Merged
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
2 changes: 1 addition & 1 deletion functions/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
Expand Down
6 changes: 3 additions & 3 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
},
"devDependencies": {
"@types/fluent-ffmpeg": "^2.1.27",
"@types/jest": "^27.4.0",
"@types/jest": "^29.5.14",
"@types/jsdom": "^21.1.7",
"@types/luxon": "^2.0.9",
"@types/object-hash": "^2.2.1",
"copyfiles": "^2.4.1",
"firebase-functions-test": "^0.3.3",
"firebase-tools": "^13.18.0",
"jest": "^27.5.1",
"jest": "^29.7.0",
"rimraf": "^3.0.2",
"ts-jest": "^27.1.3",
"ts-jest": "^29.2.5",
"typescript": "4.5.5"
},
"private": true
Expand Down
1,586 changes: 786 additions & 800 deletions functions/yarn.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const createJestConfig = nextJest({
const config = {
coverageProvider: "v8",
testEnvironment: "jsdom",
testEnvironmentOptions: {
customExportConditions: ["node", "node-addons"]
},
moduleNameMapper: {
"^components/(.*)$": "<rootDir>/components/$1"
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"@tsconfig/node16": "^1.0.2",
"@types/diff": "^5.0.2",
"@types/dompurify": "^2.3.3",
"@types/jest": "^27.4.0",
"@types/jest": "^29.5.14",
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.178",
"@types/luxon": "^2.0.9",
Expand Down Expand Up @@ -184,8 +184,8 @@
"firebase-tools": "^13.18.0",
"ini": "^1.3.5",
"inquirer": "^6.5.1",
"jest": "^27.5.1",
"jest-environment-jsdom": "^27.5.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-summary-reporter": "^0.0.2",
"js-yaml": "^4.1.0",
"lorem-ipsum": "^2.0.4",
Expand Down
3 changes: 2 additions & 1 deletion scripts/generate-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const argv = yargs(hideBin(process.argv))
default: paths.defaultStoriesConfig,
describe:
"Path to a multi-document yaml file with story configs. Each config is a map with name, folder, grouping, and figmaUrl fields."
}).argv
})
.parseSync()

generateStories(argv.template, argv.stories)
28 changes: 11 additions & 17 deletions scripts/typesense-admin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { execSync } from "child_process"
import repl from "repl"
import { Client } from "typesense"
import yargs from "yargs"
import yargs, { Arguments } from "yargs"
import { hideBin } from "yargs/helpers"
import { createClient } from "../functions/src/search/client"

declare global {
var client: Client
var client: ReturnType<typeof createClient>
}

const envs: Record<string, { url: string; key?: string; alias?: string }> = {
Expand All @@ -21,13 +20,13 @@ const envs: Record<string, { url: string; key?: string; alias?: string }> = {
}
}

type Args = { url?: string; key?: string; env?: string }
type Args = Arguments<{ url?: string; key?: string; env?: string }>
yargs(hideBin(process.argv))
.scriptName("typesense-admin")
.command(
"console",
"start a node repl with an initialized client",
() => {},
{},
(args: Args) => {
globalThis.client = resolveClient(args)
repl.start({}).setupHistory("typesense-admin.history", () => {})
Expand All @@ -36,7 +35,7 @@ yargs(hideBin(process.argv))
.command(
"create-search-key",
"create a new search key",
() => {},
{},
async (args: Args) => {
const client = resolveClient(args)
const key = await client.keys().create({
Expand All @@ -47,20 +46,15 @@ yargs(hideBin(process.argv))
console.log("Created", key.value)
}
)
.command(
"list-keys",
"list keys",
() => {},
async (args: Args) => {
const client = resolveClient(args)
console.log(await client.keys().retrieve())
}
)
.command("list-keys", "list keys", {}, async (args: Args) => {
const client = resolveClient(args)
console.log(await client.keys().retrieve())
})
.command(
"delete-key <id>",
"list keys",
() => {},
async (args: Args & { id: string }) => {
{},
async (args: Args & { id?: string }) => {
const client = resolveClient(args)
console.log(await client.keys(Number(args.id)).delete())
}
Expand Down
63 changes: 35 additions & 28 deletions tests/integrationEnvironment.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
import { Config } from "@jest/types"
import type {
JestEnvironmentConfig,
EnvironmentContext
} from "@jest/environment"
import BrowserEnvironment from "jest-environment-jsdom"
import timers from "timers"

class IntegrationEnvironment extends BrowserEnvironment {
constructor(config: Config.ProjectConfig) {
super(
Object.assign({}, config, {
globals: Object.assign({}, config.globals, {
// https://github.com/firebase/firebase-js-sdk/issues/3096#issuecomment-637584185
Uint32Array: Uint32Array,
Uint8Array: Uint8Array,
ArrayBuffer: ArrayBuffer,
constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
super(config, context)
}

// These are required to run the admin sdk in a jsdom environment
setImmediate: timers.setImmediate,
setTimeout: timers.setTimeout,
setInterval: timers.setInterval,
clearImmediate: timers.clearImmediate,
clearTimeout: timers.clearTimeout,
clearInterval: timers.clearInterval,
async setup() {
await super.setup()

/** jsdom's Blob implementation does not work with firebase/storage.
* firebase/storage *does* work with a fallback if Blob is not
* available, so removing the global is a hack to get storage tests
* working. We'll need a better solution when tests need to use Blobs.
* */
Blob: undefined
})
})
)
}
// https://github.com/firebase/firebase-js-sdk/issues/3096#issuecomment-637584185
this.global.Uint32Array = Uint32Array
this.global.Uint8Array = Uint8Array
this.global.ArrayBuffer = ArrayBuffer

async setup() {}
// These are required to run the admin sdk in a jsdom environment
this.global.setImmediate =
timers.setImmediate as typeof globalThis.setImmediate
this.global.setTimeout = timers.setTimeout as typeof globalThis.setTimeout
this.global.setInterval =
timers.setInterval as typeof globalThis.setInterval
this.global.clearImmediate = timers.clearImmediate
this.global.clearTimeout =
timers.clearTimeout as typeof globalThis.clearTimeout
this.global.clearInterval =
timers.clearInterval as typeof globalThis.clearInterval

async teardown() {}
/** jsdom's Blob implementation does not work with firebase/storage.
* firebase/storage *does* work with a fallback if Blob is not
* available, so removing the global is a hack to get storage tests
* working. We'll need a better solution when tests need to use Blobs.
* */
;(this.global as any).Blob = undefined
}

async teardown() {
await super.teardown()
}
}

export default IntegrationEnvironment
3 changes: 3 additions & 0 deletions tests/jest.integration.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ runAgainstEmulators()
const config: Config.InitialOptions = {
clearMocks: true,
testEnvironment: "./tests/integrationEnvironment.ts",
testEnvironmentOptions: {
customExportConditions: ["node", "node-addons"]
},
rootDir: "..",
testPathIgnorePatterns: [
"/node_modules/",
Expand Down
3 changes: 3 additions & 0 deletions tests/jest.seed.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ runAgainstEmulators()
const config: Config.InitialOptions = {
clearMocks: true,
testEnvironment: "./tests/integrationEnvironment.ts",
testEnvironmentOptions: {
customExportConditions: ["node", "node-addons"]
},
rootDir: "..",
roots: ["tests/seed"]
}
Expand Down
5 changes: 4 additions & 1 deletion tests/jest.system.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const config: Config.InitialOptions = {
clearMocks: true,
rootDir: "..",
roots: ["tests/system"],
testEnvironment: "./tests/integrationEnvironment.ts"
testEnvironment: "./tests/integrationEnvironment.ts",
testEnvironmentOptions: {
customExportConditions: ["node", "node-addons"]
}
}

// See https://nextjs.org/docs/advanced-features/compiler#jest
Expand Down
Loading
Loading