File tree Expand file tree Collapse file tree 8 files changed +4008
-3
lines changed Expand file tree Collapse file tree 8 files changed +4008
-3
lines changed Original file line number Diff line number Diff line change 4646 "test:env:node-ts" : " yarn --cwd tests/env/typescript-node start" ,
4747 "test:env:nodejs" : " yarn build && node tests/env/node/index.js && node tests/env/node/getting_started.js" ,
4848 "test:env:esm" : " yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start" ,
49+ "test:env:nitro-app" : " yarn build && yarn --cwd tests/env/nitro-app test" ,
4950 "size" : " node scripts/file-size ./dist/bundles/meilisearch.esm.min.js ./dist/bundles/meilisearch.umd.min.js" ,
5051 "style" : " yarn lint" ,
5152 "style:fix" : " yarn lint:fix" ,
Original file line number Diff line number Diff line change 1- import 'cross-fetch/polyfill'
21import { FetchError } from '../types'
32
43class MeiliSearchCommunicationError extends Error {
Original file line number Diff line number Diff line change 1- import 'cross-fetch/polyfill'
2-
31import { Config , EnqueuedTaskObject } from './types'
42import { PACKAGE_VERSION } from './package-version'
53
@@ -120,6 +118,10 @@ class HttpRequests {
120118 body ?: any
121119 config ?: Record < string , any >
122120 } ) {
121+ if ( typeof fetch === 'undefined' ) {
122+ require ( 'cross-fetch/polyfill' )
123+ }
124+
123125 const constructURL = new URL ( url , this . url )
124126 if ( params ) {
125127 const queryParams = new URLSearchParams ( )
Original file line number Diff line number Diff line change 1+ node_modules
2+ * .log *
3+ .nitro
4+ .cache
5+ .output
Original file line number Diff line number Diff line change 1+ {
2+ "private" : true ,
3+ "scripts" : {
4+ "test" : " yarn build && jest" ,
5+ "dev" : " npx nitropack dev" ,
6+ "build" : " npx nitropack build" ,
7+ "preview" : " node .output/server/index.mjs"
8+ },
9+ "dependencies" : {
10+ "meilisearch" : " file:../../../" ,
11+ "nitropack" : " latest"
12+ },
13+ "devDependencies" : {
14+ "jest" : " 29.5.0"
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ import { MeiliSearch } from 'meilisearch'
2+
3+ const meilisearch = new MeiliSearch ( {
4+ host : 'http://localhost:7700' ,
5+ apiKey : 'masterKey' ,
6+ } )
7+
8+ export default defineEventHandler ( async ( ) => {
9+ try {
10+ const health = await meilisearch . isHealthy ( )
11+
12+ return { health }
13+ } catch ( error ) {
14+ throw createError ( {
15+ statusCode : 500 ,
16+ statusMessage : 'Unexpected Error' ,
17+ } )
18+ }
19+ } )
Original file line number Diff line number Diff line change 1+ const { spawn } = require ( 'child_process' )
2+
3+ let server
4+
5+ beforeAll ( ( ) => {
6+ server = spawn ( 'node' , [ '.output/server/index.mjs' ] )
7+ } )
8+
9+ afterAll ( ( ) => {
10+ server . kill ( )
11+ } )
12+
13+ describe ( 'Meilisearch JS w/ Nitro App Server Browser test' , ( ) => {
14+ it ( 'Should have created an index and displayed it' , async ( ) => {
15+ await new Promise ( ( next ) => {
16+ server . stdout . on ( 'data' , ( ) => {
17+ next ( )
18+ server . stdout . removeAllListeners ( 'data' )
19+ } )
20+ } )
21+ const response = await fetch ( 'http://[::]:3000' )
22+ const data = await response . json ( )
23+
24+ expect ( data . health ) . toBe ( true )
25+ } )
26+ } )
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments