@@ -38,6 +38,7 @@ describe("updateTsConfig", () => {
3838
3939 test ( "installing workers types" , async ( ) => {
4040 ctx . template . installWorkersTypes = true ;
41+ ctx . template . skipWranglerTypegen = true ;
4142 await updateTsConfig ( ctx ) ;
4243
4344 expect ( writeFile ) . toHaveBeenCalled ( ) ;
@@ -55,6 +56,7 @@ describe("updateTsConfig", () => {
5556
5657 test ( "latest entrypoint not found" , async ( ) => {
5758 ctx . template . installWorkersTypes = true ;
59+ ctx . template . skipWranglerTypegen = true ;
5860 vi . mocked ( getLatestTypesEntrypoint ) . mockReturnValue ( null ) ;
5961 await updateTsConfig ( ctx ) ;
6062
@@ -63,6 +65,7 @@ describe("updateTsConfig", () => {
6365
6466 test ( "don't clobber existing entrypoints" , async ( ) => {
6567 ctx . template . installWorkersTypes = true ;
68+ ctx . template . skipWranglerTypegen = true ;
6669 vi . mocked ( readFile ) . mockImplementation (
6770 ( ) =>
6871 `{ "compilerOptions": { "types" : ["@cloudflare/workers-types/2021-03-20"]} }` ,
@@ -74,17 +77,36 @@ describe("updateTsConfig", () => {
7477 ) ;
7578 } ) ;
7679
77- test ( "will remove workers-types when generating types" , async ( ) => {
78- vi . mocked ( readFile ) . mockImplementation (
79- ( ) =>
80- `{ "compilerOptions": { "types" : ["@cloudflare/workers-types/2021-03-20"]} }` ,
81- ) ;
80+ test ( "will remove workers-types when generating types, if generated types include runtime types" , async ( ) => {
81+ vi . mocked ( readFile ) . mockImplementation ( ( path ) => {
82+ console . log ( "path" , path ) ;
83+ if ( path . includes ( "tsconfig.json" ) ) {
84+ return `{ "compilerOptions": { "types" : ["@cloudflare/workers-types/2021-03-20"]} }` ;
85+ } else {
86+ return "// Runtime types generated with workerd" ;
87+ }
88+ } ) ;
8289 await updateTsConfig ( ctx ) ;
8390 expect ( vi . mocked ( writeFile ) . mock . calls [ 0 ] [ 1 ] ) . not . toContain (
8491 `"@cloudflare/workers-types/2021-03-20"` ,
8592 ) ;
8693 } ) ;
8794
95+ test ( "will NOT remove workers-types when generating types, if generated types don't include runtime types" , async ( ) => {
96+ vi . mocked ( readFile ) . mockImplementation ( ( path ) => {
97+ if ( path . includes ( "tsconfig.json" ) ) {
98+ return `{ "compilerOptions": { "types" : ["@cloudflare/workers-types/2021-03-20"]} }` ;
99+ } else {
100+ return "no runtime types here" ;
101+ }
102+ } ) ;
103+ await updateTsConfig ( ctx ) ;
104+
105+ expect ( vi . mocked ( writeFile ) . mock . calls [ 0 ] [ 1 ] ) . toContain (
106+ `"@cloudflare/workers-types/2021-03-20"` ,
107+ ) ;
108+ } ) ;
109+
88110 test ( "will add generated types file" , async ( ) => {
89111 await updateTsConfig ( ctx ) ;
90112 expect ( vi . mocked ( writeFile ) . mock . calls [ 0 ] [ 1 ] ) . toContain (
0 commit comments