Skip to content

Commit

Permalink
fix: Fixed e2e tests. (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Insogna authored Jun 6, 2023
1 parent 52add1b commit a23fb70
Show file tree
Hide file tree
Showing 14 changed files with 1,705 additions and 1,378 deletions.
6 changes: 0 additions & 6 deletions packages/docs/next.config.js

This file was deleted.

14 changes: 14 additions & 0 deletions packages/docs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import nextra from 'nextra'
import {nodeTypes} from '@mdx-js/mdx'
import rehypeRaw from 'rehype-raw'

const withNextra = nextra({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.jsx',
mdxOptions: {
// See: https://github.com/mdx-js/mdx/issues/1820
rehypePlugins: [[rehypeRaw, { passThrough: nodeTypes }]]
}
})

export default withNextra()
4 changes: 3 additions & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@mdx-js/mdx": "^2.3.0",
"@orama/orama": "workspace:*",
"@orama/plugin-match-highlight": "workspace:*",
"@orama/plugin-nextra": "workspace:*",
Expand All @@ -22,6 +23,7 @@
"nextra-theme-docs": "^2.2.19",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.8.0"
"react-icons": "^4.8.0",
"rehype-raw": "^6.1.1"
}
}
3 changes: 2 additions & 1 deletion packages/orama/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"test": "c8 -c tests/config/c8-local.json tap --rcfile=tests/config/tap.yml tests/*.test.ts",
"test:ci": "c8 -c tests/config/c8-ci.json tap --rcfile=tests/config/tap.yml --no-color tests/*.test.ts",
"test:smoke": "tap --rcfile=tests/config/tap.yml tests/smoke/*.test.ts",
"ci": "npm run build && npm run test:ci && npm run test:smoke"
"ci": "npm run build && npm run test:ci && npm run test:smoke",
"pack": "pnpm pack --pack-destination ../../dist"
},
"keywords": [
"full-text search",
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"build": "swc --delete-dir-on-start --extensions .ts -d dist src",
"postbuild": "tsc -p . --emitDeclarationOnly",
"test": "node --loader=tsx --no-warnings=loader --test ./test/integration.ts | tap-mocha-reporter spec",
"lint": "eslint src --ext .js,.ts,.tsx,.cts"
"lint": "eslint src --ext .js,.ts,.tsx,.cts",
"pack": "pnpm pack --pack-destination ../../dist"
},
"dependencies": {
"@orama/orama": "workspace:*",
Expand Down
27 changes: 16 additions & 11 deletions packages/plugin-astro/test/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { create as createOramaDB, load as loadOramaDB, Schema, search } from '@o
import assert from 'node:assert'
import { exec, ExecException } from 'node:child_process'
import { existsSync } from 'node:fs'
import { cp, readFile, rm } from 'node:fs/promises'
import { cp, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { dirname, resolve } from 'node:path'
import { chdir } from 'node:process'
Expand All @@ -17,7 +17,7 @@ interface Execution {
}

const sandboxSource = fileURLToPath(new URL('./sandbox', import.meta.url))
const sandbox = resolve(tmpdir(), `orama-plugin-astro-${Date.now()}`)
const sandbox = process.env.KEEP_SANDBOX ? '/tmp/orama-astro-sandbox' : resolve(tmpdir(), `orama-plugin-astro-${Date.now()}`)

async function cleanup(): Promise<void> {
await rm(sandbox, { force: true, recursive: true })
Expand Down Expand Up @@ -50,20 +50,22 @@ async function execute(command: string, cwd?: string): Promise<Execution> {
await cleanup()

await test('plugin is able to generate orama DB at build time', async () => {
// Prepare the plugin
// Obtain general information
const pluginInfo: Record<string, string> = JSON.parse(
await readFile(fileURLToPath(new URL(`../package.json`, import.meta.url)), 'utf-8')
await readFile(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf-8')
)
const pluginPath = fileURLToPath(new URL(`../orama-plugin-astro-${pluginInfo.version}.tgz`, import.meta.url))
const packResult = await execute('pnpm pack')
assert.equal(packResult.code, 0)
const rootDir = dirname(fileURLToPath(new URL(`../..`, import.meta.url)))
const version = pluginInfo.version

// Prepare the sandbox
const packageJsonPath = resolve(sandbox, 'package.json')
await cp(sandboxSource, sandbox, { recursive: true })
await cp(pluginPath, resolve(sandbox, 'plugin.tgz'))
await rm(pluginPath)

chdir(sandbox)
console.log(`Sandbox created in ${sandbox}`)

// Update dependencies location
const packageJson = await readFile(packageJsonPath, 'utf-8')
await writeFile(packageJsonPath, packageJson.replace(/@ROOT@/g, rootDir).replace(/@VERSION@/g, version), 'utf-8')

// Install dependencies
const installResult = await execute('pnpm install', sandbox)
Expand Down Expand Up @@ -129,4 +131,7 @@ await test('generated DBs have indexed pages content', async () => {
assert.ok(dynamicTestMissingSearchResult.count === 0)
})

await cleanup()
if(!process.env.KEEP_SANDBOX) {
await cleanup()
}

10 changes: 8 additions & 2 deletions packages/plugin-astro/test/sandbox/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
{
"name": "@orama/plugin-astro-sandbox",
"type": "module",
"version": "1.0.0-beta.4",
"version": "@VERSION@",
"private": true,
"scripts": {
"build": "exit 0",
"test": "exit 0"
},
"dependencies": {
"@orama/plugin-astro": "./plugin.tgz",
"@orama/plugin-astro": "^@VERSION@",
"astro": "^2.0.2"
},
"pnpm": {
"overrides": {
"@orama/orama": "@ROOT@/dist/orama-orama-@[email protected]",
"@orama/plugin-astro": "@ROOT@/dist/orama-plugin-astro-@[email protected]"
}
}
}
3 changes: 2 additions & 1 deletion packages/plugin-docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"test": "node --loader=tsx --no-warnings=loader --test ./test/integration.ts | tap-mocha-reporter spec",
"format": "prettier -w src",
"lint": "eslint src --ext .js,.ts,.tsx,.cts",
"changelog": "auto-changelog -p"
"changelog": "auto-changelog -p",
"pack": "pnpm pack --pack-destination ../../dist"
},
"dependencies": {
"@algolia/autocomplete-js": "^1.7.2",
Expand Down
28 changes: 16 additions & 12 deletions packages/plugin-docusaurus/test/integration.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import assert from 'node:assert'
import { exec, ExecException } from 'node:child_process'
import { existsSync } from 'node:fs'
import { cp, readdir, readFile, rm } from 'node:fs/promises'
import { cp, readdir, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { resolve } from 'node:path'
import { dirname, resolve } from 'node:path'
import { chdir } from 'node:process'
import { test } from 'node:test'
import { fileURLToPath } from 'node:url'
Expand All @@ -21,7 +21,7 @@ interface Execution {
}

const sandboxSource = fileURLToPath(new URL('./sandbox', import.meta.url))
const sandbox = resolve(tmpdir(), `orama-plugin-docusaurus-${Date.now()}`)
const sandbox = process.env.KEEP_SANDBOX ? '/tmp/orama-docusaurus-sandbox' : resolve(tmpdir(), `orama-plugin-docusaurus-${Date.now()}`)

async function cleanup(): Promise<void> {
await rm(sandbox, { force: true, recursive: true })
Expand Down Expand Up @@ -58,23 +58,25 @@ async function execute(command: string, cwd?: string): Promise<Execution> {
await cleanup()

await test('plugin is able to generate orama DB at build time', async () => {
// Prepare the plugin
// Obtain general information
const pluginInfo: Record<string, string> = JSON.parse(
await readFile(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf-8')
)
const pluginPath = fileURLToPath(new URL(`../orama-plugin-docusaurus-${pluginInfo.version}.tgz`, import.meta.url))
const packResult = await execute('pnpm pack')
assert.equal(packResult.code, 0)
const rootDir = dirname(fileURLToPath(new URL(`../..`, import.meta.url)))
const version = pluginInfo.version

// Prepare the sandbox
const packageJsonPath = resolve(sandbox, 'package.json')
await cp(sandboxSource, sandbox, { recursive: true })
await cp(pluginPath, resolve(sandbox, 'plugin.tgz'))
await rm(pluginPath)

chdir(sandbox)
console.log(`Sandbox created in ${sandbox}`)

// Update dependencies location
const packageJson = await readFile(packageJsonPath, 'utf-8')
await writeFile(packageJsonPath, packageJson.replace(/@ROOT@/g, rootDir).replace(/@VERSION@/g, version), 'utf-8')

// Install dependencies
const installResult = await execute('npm install', sandbox)
const installResult = await execute('pnpm install', sandbox)
assert.equal(installResult.code, 0)

// docusaurus build is successful
Expand Down Expand Up @@ -118,4 +120,6 @@ await test('generated DBs have indexed pages content', async () => {
assert.ok(turtleSearchResult.count === 0)
})

await cleanup()
if(!process.env.KEEP_SANDBOX) {
await cleanup()
}
47 changes: 45 additions & 2 deletions packages/plugin-docusaurus/test/sandbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orama/plugin-docusaurus-sandbox",
"version": "1.0.0-beta.4",
"version": "@VERSION@",
"private": true,
"scripts": {
"build": "exit 0",
Expand All @@ -10,9 +10,52 @@
"@docusaurus/core": "^2.3.1",
"@docusaurus/preset-classic": "^2.3.1",
"@docusaurus/theme-common": "^2.2.0",
"@docusaurus/types": "^2.4.1",
"@mdx-js/react": "^1.6.22",
"@orama/plugin-docusaurus": "./plugin.tgz",
"@orama/plugin-docusaurus": "^@VERSION@",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"pnpm": {
"overrides": {
"@orama/orama": "@ROOT@/dist/orama-orama-@[email protected]",
"@orama/plugin-docusaurus": "@ROOT@/dist/orama-plugin-docusaurus-@[email protected]",
"@orama/plugin-match-highlight": "@ROOT@/dist/orama-plugin-match-highlight-@[email protected]",
"@orama/plugin-parsedoc": "@ROOT@/dist/orama-plugin-parsedoc-@[email protected]"
},
"packageExtensions": {
"@docusaurus/theme-live-codeblock": {
"peerDependencies": {
"@docusaurus/theme-common": "*"
},
"dependencies": {
"@docusaurus/theme-common": "*"
}
},
"@docusaurus/preset-classic": {
"peerDependencies": {
"@docusaurus/theme-common": "*"
},
"dependencies": {
"@docusaurus/theme-common": "*"
}
},
"@docusaurus/theme-classic": {
"peerDependencies": {
"@docusaurus/theme-common": "*"
},
"dependencies": {
"@docusaurus/theme-common": "*"
}
},
"@docusaurus/theme-search-algolia": {
"peerDependencies": {
"@docusaurus/theme-common": "*"
},
"dependencies": {
"@docusaurus/theme-common": "*"
}
}
}
}
}
3 changes: 2 additions & 1 deletion packages/plugin-match-highlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"dev": "swc --delete-dir-on-start -s -w --extensions .ts,.cts -d dist src",
"build": "swc --delete-dir-on-start --extensions .ts,.cts -d dist src",
"postbuild": "tsc -p . --emitDeclarationOnly && tsc -p tsconfig.cjs.json --emitDeclarationOnly && mv dist/commonjs.js dist/commonjs.cjs && mv dist/commonjs.js.map dist/commonjs.cjs.map",
"test": "c8 -c test/config/c8.json tap --rcfile=test/config/tap.yml test/*.test.ts"
"test": "c8 -c test/config/c8.json tap --rcfile=test/config/tap.yml test/*.test.ts",
"pack": "pnpm pack --pack-destination ../../dist"
},
"dependencies": {
"@orama/orama": "workspace:*"
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-parsedoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"dev": "swc --delete-dir-on-start -s -w --extensions .ts,.cts -d dist src",
"build": "swc --delete-dir-on-start --extensions .ts,.cts -d dist src",
"postbuild": "tsc -p . --emitDeclarationOnly && tsc -p tsconfig.cjs.json --emitDeclarationOnly && mv dist/commonjs.js dist/commonjs.cjs && mv dist/commonjs.js.map dist/commonjs.cjs.map",
"test": "c8 -c test/config/c8.json tap --rcfile=test/config/tap.yml test/*.test.ts"
"test": "c8 -c test/config/c8.json tap --rcfile=test/config/tap.yml test/*.test.ts",
"pack": "pnpm pack --pack-destination ../../dist"
},
"dependencies": {
"@orama/orama": "workspace:*",
Expand Down
Loading

1 comment on commit a23fb70

@vercel
Copy link

@vercel vercel bot commented on a23fb70 Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.