File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,8 +24,13 @@ export default function storage(nitro: Nitro) {
2424
2525 const driverImports = [ ...new Set ( mounts . map ( ( m ) => m . driver ) ) ] ;
2626
27+ const tracingEnabled = ! ! (
28+ typeof nitro . options . tracingChannel === "object" && nitro . options . tracingChannel ?. unstorage
29+ ) ;
30+
2731 return /* js */ `
2832import { createStorage } from 'unstorage'
33+ ${ tracingEnabled ? `import { withTracing } from 'unstorage/tracing'` : "" }
2934import { assets } from '#nitro/virtual/server-assets'
3035
3136${ driverImports . map ( ( i ) => genImport ( i , genSafeVariableName ( i ) ) ) . join ( "\n" ) }
@@ -39,7 +44,7 @@ export function initStorage() {
3944 `storage.mount('${ m . path } ', ${ genSafeVariableName ( m . driver ) } (${ JSON . stringify ( m . opts ) } ))`
4045 )
4146 . join ( "\n" ) }
42- return storage
47+ return ${ tracingEnabled ? "withTracing( storage)" : "storage" }
4348}
4449` ;
4550 } ,
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export async function resolveTracingOptions(options: NitroOptions) {
55 options . tracingChannel = {
66 srvx : true ,
77 h3 : true ,
8+ unstorage : true ,
89 ...( typeof options . tracingChannel === "object" ? options . tracingChannel : { } ) ,
910 } ;
1011 options . plugins = options . plugins || [ ] ;
Original file line number Diff line number Diff line change @@ -1038,6 +1038,7 @@ export interface ServerAssetDir {
10381038export interface TracingOptions {
10391039 srvx ?: boolean ;
10401040 h3 ?: boolean ;
1041+ unstorage ?: boolean ;
10411042}
10421043
10431044/**
Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from "vitest" ;
2+ import type { Nitro } from "nitro/types" ;
3+
4+ import storage from "../../src/build/virtual/storage.ts" ;
5+
6+ function createNitroStub ( tracingChannel : Nitro [ "options" ] [ "tracingChannel" ] ) : Nitro {
7+ return {
8+ options : {
9+ dev : true ,
10+ preset : "nitro-dev" ,
11+ storage : { } ,
12+ devStorage : { } ,
13+ tracingChannel,
14+ } ,
15+ } as unknown as Nitro ;
16+ }
17+
18+ describe ( "virtual/storage template" , ( ) => {
19+ it ( "does not wrap storage when tracingChannel is disabled" , ( ) => {
20+ const template = storage ( createNitroStub ( undefined ) ) . template ( ) ;
21+ expect ( template ) . not . toContain ( "withTracing" ) ;
22+ expect ( template ) . not . toContain ( "unstorage/tracing" ) ;
23+ expect ( template ) . toContain ( "return storage" ) ;
24+ } ) ;
25+
26+ it ( "does not wrap storage when tracingChannel.unstorage is false" , ( ) => {
27+ const template = storage (
28+ createNitroStub ( { srvx : true , h3 : true , unstorage : false } )
29+ ) . template ( ) ;
30+ expect ( template ) . not . toContain ( "withTracing" ) ;
31+ } ) ;
32+
33+ it ( "wraps storage with withTracing when tracingChannel.unstorage is true" , ( ) => {
34+ const template = storage ( createNitroStub ( { srvx : true , h3 : true , unstorage : true } ) ) . template ( ) ;
35+ expect ( template ) . toContain ( `import { withTracing } from 'unstorage/tracing'` ) ;
36+ expect ( template ) . toContain ( "return withTracing(storage)" ) ;
37+ } ) ;
38+ } ) ;
You can’t perform that action at this time.
0 commit comments