File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
55import fse from 'fs-extra' ;
66import { expect } from 'vitest' ;
77
8- import { readFixture } from './fixtures.js' ;
8+ import { readFixture , writeFixture } from './fixtures.js' ;
99import { packageJsonAt } from './utils.js' ;
1010
1111interface AssertGeneratedOptions {
@@ -162,6 +162,12 @@ export async function matchesFixture(
162162 }
163163
164164 let sourceContents = ( await fs . readFile ( testFilePath ) ) . toString ( ) ;
165+
166+ if ( process . env . WRITE_FIXTURES ) {
167+ console . info ( `Writing fixture: ${ fixtureFile } in scenario: ${ scenario } ` ) ;
168+ await writeFixture ( fixtureFile , sourceContents , { scenario } ) ;
169+ }
170+
165171 let fixtureContents = await readFixture ( fixtureFile , { scenario } ) ;
166172
167173 /**
Original file line number Diff line number Diff line change @@ -44,6 +44,25 @@ export async function readFixture(
4444 return contents . toString ( ) ;
4545}
4646
47+ export async function writeFixture (
48+ /**
49+ * Which file within in the fixture-set / scenario to read
50+ */
51+ file : string ,
52+ contents : string ,
53+ options ?: {
54+ /**
55+ * Which fixture set to use
56+ */
57+ scenario ?: string } ) {
58+
59+
60+ let scenario = options ?. scenario ?? 'default' ;
61+ let fixtureFilePath = path . isAbsolute ( file ) ? file : path . join ( fixturesPath , scenario , file ) ;
62+
63+ await fs . writeFile ( fixtureFilePath , contents ) ;
64+ }
65+
4766export async function copyFixture (
4867 /**
4968 * Which file within the fixture-set / scenario to copy
You can’t perform that action at this time.
0 commit comments