Skip to content

Commit

Permalink
fix(fixtures): always match empty file for undefined snapshots (#4923)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso authored Nov 23, 2024
1 parent 9d0e5b9 commit e7fb97c
Show file tree
Hide file tree
Showing 192 changed files with 24 additions and 33 deletions.
16 changes: 9 additions & 7 deletions packages/@lwc/engine-server/src/__tests__/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function testFixtures(options?: RollupLwcOptions) {
const message = err?.message?.match(/(LWC\d+[^\n]+)/)?.[1];
return {
'expected.html': '',
'error.txt': message ?? '',
'error.txt': message,
};
}

Expand All @@ -136,10 +136,12 @@ function testFixtures(options?: RollupLwcOptions) {
let result;
let err;
try {
result = lwcEngineServer!.renderComponent(
module!.tagName,
module!.default,
config?.props ?? {}
result = formatHTML(
lwcEngineServer!.renderComponent(
module!.tagName,
module!.default,
config?.props ?? {}
)
);
} catch (_err: any) {
if (_err.name === 'AssertionError') {
Expand All @@ -153,8 +155,8 @@ function testFixtures(options?: RollupLwcOptions) {
});

return {
'expected.html': result ? formatHTML(result) : '',
'error.txt': err ?? '',
'expected.html': result,
'error.txt': err,
};
}
);
Expand Down
34 changes: 14 additions & 20 deletions packages/@lwc/ssr-compiler/src/__tests__/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,25 @@ describe.runIf(process.env.TEST_SSR_COMPILER).concurrent('fixtures', () => {
const module = (await import(compiledFixturePath)) as FixtureModule;

let result;
let error;

try {
result = await serverSideRenderComponent(
module!.tagName,
module!.default,
config?.props ?? {},
SSR_MODE
result = formatHTML(
await serverSideRenderComponent(
module!.tagName,
module!.default,
config?.props ?? {},
SSR_MODE
)
);
} catch (err: any) {
return {
[errorFile]: err.message,
[expectedFile]: '',
};
error = err.message;
}

try {
return {
[errorFile]: '',
[expectedFile]: formatHTML(result),
};
} catch (_err: any) {
return {
[errorFile]: `Test helper could not format HTML:\n\n${result}`,
[expectedFile]: '',
};
}
return {
[errorFile]: error,
[expectedFile]: result,
};
}
);
});
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
7 changes: 1 addition & 6 deletions scripts/test-utils/test-fixture-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,8 @@ export function testFixtureDir<T extends TestFixtureConfig>(

for (const [outputName, content] of Object.entries(outputs)) {
const outputPath = path.resolve(dirname, outputName);

try {
if (content === undefined) {
expect(fs.existsSync(outputPath)).toBe(false);
} else {
await expect(content).toMatchFileSnapshot(outputPath);
}
await expect(content ?? '').toMatchFileSnapshot(outputPath);
} catch (err) {
if (typeof err === 'object' && err !== null) {
// Hide unhelpful noise in the stack trace
Expand Down

0 comments on commit e7fb97c

Please sign in to comment.