Adjust tests for Vitest 3

This commit is contained in:
Valentin Palkovic 2025-01-03 11:53:19 +01:00
parent 09196b1fe7
commit e61762b41a
9 changed files with 132 additions and 134 deletions

View File

@ -104,16 +104,14 @@ beforeEach(() => {
* Skipping this test, because it causes a cyclical dependency error, where core depends on docs &
* blocks This was done to avoid a conflict in the CPC work, we should revisit this.
*/
describe.skip(
'PreviewWeb',
() => {
describe('PreviewWeb', { skip: true }, () => {
describe('initial render', () => {
it('renders story mode through the stack', async () => {
const { DocsRenderer } = await import('../../../../../addons/docs/src/index');
projectAnnotations.parameters.docs.renderer = () => new DocsRenderer() as any;
projectAnnotations.renderToCanvas.mockImplementationOnce(
({ storyFn }: RenderContext<any>) => storyFn()
projectAnnotations.renderToCanvas.mockImplementationOnce(({ storyFn }: RenderContext<any>) =>
storyFn()
);
document.location.search = '?id=component-one--a';
await new PreviewWeb(importFn, getProjectAnnotations).ready();
@ -206,8 +204,8 @@ describe.skip(
await preview.ready();
await waitForRender();
projectAnnotations.renderToCanvas.mockImplementationOnce(
({ storyFn }: RenderContext<any>) => storyFn()
projectAnnotations.renderToCanvas.mockImplementationOnce(({ storyFn }: RenderContext<any>) =>
storyFn()
);
projectAnnotations.decorators[0].mockClear();
mockChannel.emit.mockClear();
@ -220,6 +218,4 @@ describe.skip(
});
});
});
},
{ retry: 0 }
);
});

View File

@ -18,20 +18,20 @@ describe('angular component properties', () => {
expect(true).toEqual(true);
});
// TODO: Fix this test
// it(`${testEntry.name}`, () => {
// it(`${testEntry.name}`, async () => {
// const inputPath = join(testDir, testFile);
// // snapshot the output of compodoc
// const compodocOutput = runCompodoc(inputPath);
// const compodocJson = JSON.parse(compodocOutput);
// expect(compodocJson).toMatchFileSnapshot(
// await expect(compodocJson).toMatchFileSnapshot(
// join(testDir, `compodoc-${SNAPSHOT_OS}.snapshot`)
// );
// // snapshot the output of addon-docs angular-properties
// const componentData = findComponentByName('InputComponent', compodocJson);
// const argTypes = extractArgTypesFromData(componentData);
// expect(argTypes).toMatchFileSnapshot(join(testDir, 'argtypes.snapshot'));
// await expect(argTypes).toMatchFileSnapshot(join(testDir, 'argtypes.snapshot'));
// });
}
}

View File

@ -24,8 +24,8 @@ readdirSync(fixturesDir).forEach((transformName) => {
.filter((fileName) => inputRegExp.test(fileName))
.forEach((fileName) => {
const inputPath = join(transformFixturesDir, fileName);
it(`transforms correctly using "${fileName}" data`, () =>
expect(
it(`transforms correctly using "${fileName}" data`, async () =>
await expect(
applyTransform(require(join(__dirname, '..', transformName)), null, {
path: inputPath,
source: fs.readFileSync(inputPath, 'utf8'),

View File

@ -25,7 +25,7 @@ async function generate(filePath: string) {
it(`${fixtureFile}`, async () => {
const inputPath = join(transformFixturesDir, fixtureFile);
const code = await generate(inputPath);
expect(code).toMatchFileSnapshot(inputPath.replace(inputRegExp, '.snapshot'));
await expect(code).toMatchFileSnapshot(inputPath.replace(inputRegExp, '.snapshot'));
});
});
});

View File

@ -77,8 +77,8 @@ describe('renders', () => {
expect(screen.getByTestId('loaded-data').textContent).toEqual('loaded data');
});
it('should throw an error in play function', () => {
expect(() => MountInPlayFunctionThrow.run()).rejects.toThrowError('Error thrown in play');
it('should throw an error in play function', async () => {
await expect(() => MountInPlayFunctionThrow.run()).rejects.toThrowError('Error thrown in play');
});
it('should call and compose loaders data', async () => {

View File

@ -71,12 +71,12 @@ describe('react component properties', () => {
if (skippedTests.includes(testEntry.name)) {
it.skip(`${testEntry.name}`, () => {});
} else {
it(`${testEntry.name}`, () => {
it(`${testEntry.name}`, async () => {
const inputPath = join(testDir, testFile);
// snapshot the output of babel-plugin-react-docgen
const docgenPretty = annotateWithDocgen(inputPath);
expect(docgenPretty).toMatchFileSnapshot(join(testDir, 'docgen.snapshot'));
await expect(docgenPretty).toMatchFileSnapshot(join(testDir, 'docgen.snapshot'));
// transform into an uglier format that's works with require-from-string
const docgenModule = transformToModule(docgenPretty);
@ -84,7 +84,7 @@ describe('react component properties', () => {
// snapshot the output of component-properties/react
const { component } = requireFromString(docgenModule, inputPath);
const properties = extractProps(component);
expect(properties).toMatchFileSnapshot(join(testDir, 'properties.snapshot'));
await expect(properties).toMatchFileSnapshot(join(testDir, 'properties.snapshot'));
// snapshot the output of `extractArgTypes`
const argTypes = extractArgTypes(component);
@ -93,7 +93,7 @@ describe('react component properties', () => {
argTypes,
parameters,
} as unknown as StoryContext<Renderer>);
expect(rows).toMatchFileSnapshot(join(testDir, 'argTypes.snapshot'));
await expect(rows).toMatchFileSnapshot(join(testDir, 'argTypes.snapshot'));
});
}
}

View File

@ -46,7 +46,7 @@ describe('web-components component properties', () => {
const testDir = join(fixturesDir, testEntry.name);
const testFile = readdirSync(testDir).find((fileName) => inputRegExp.test(fileName));
if (testFile) {
it(`${testEntry.name}`, () => {
it(`${testEntry.name}`, async () => {
const inputPath = join(testDir, testFile);
// snapshot the output of wca
@ -55,11 +55,13 @@ describe('web-components component properties', () => {
customElements.tags.forEach((tag: any) => {
tag.path = 'dummy-path-to-component';
});
expect(customElements).toMatchFileSnapshot(join(testDir, 'custom-elements.snapshot'));
await expect(customElements).toMatchFileSnapshot(
join(testDir, 'custom-elements.snapshot')
);
// snapshot the properties
const properties = extractArgTypesFromElements('input', customElements);
expect(properties).toMatchFileSnapshot(join(testDir, 'properties.snapshot'));
await expect(properties).toMatchFileSnapshot(join(testDir, 'properties.snapshot'));
});
}
}

View File

@ -15,7 +15,7 @@ const compose = (entry) => {
return composeStories(entry);
} catch (e) {
throw new Error(
`There was an issue composing stories for the module: ${JSON.stringify(entry)}, ${e}`,
`There was an issue composing stories for the module: ${JSON.stringify(entry)}, ${e}`
);
}
};
@ -23,7 +23,7 @@ const compose = (entry) => {
function getAllStoryFiles() {
// Place the glob you want to match your stories files
const storyFiles = glob.sync(
path.join(__dirname, 'stories/**/*.{stories,story}.{js,jsx,mjs,ts,tsx}'),
path.join(__dirname, 'stories/**/*.{stories,story}.{js,jsx,mjs,ts,tsx}')
);
return storyFiles.map((filePath) => {
@ -45,7 +45,7 @@ describe('Stories Snapshots', () => {
if (stories.length <= 0) {
throw new Error(
`No stories found for this module: ${title}. Make sure there is at least one valid story for this module.`,
`No stories found for this module: ${title}. Make sure there is at least one valid story for this module.`
);
}
@ -157,7 +157,7 @@ const compose = (entry) => {
return composeStories(entry);
} catch (error) {
throw new Error(
`There was an issue composing stories for the module: ${JSON.stringify(entry)}, ${error}`,
`There was an issue composing stories for the module: ${JSON.stringify(entry)}, ${error}`
);
}
};
@ -166,7 +166,7 @@ function getAllStoryFiles() {
const storyFiles = Object.entries(
import.meta.glob('./stories/**/*.(stories|story).@(js|jsx|mjs|ts|tsx)', {
eager: true,
}),
})
);
return storyFiles.map(([filePath, storyFile]) => {
@ -185,7 +185,7 @@ describe('Stories Snapshots', () => {
if (stories.length <= 0) {
throw new Error(
`No stories found for this module: ${title}. Make sure there is at least one valid story for this module.`,
`No stories found for this module: ${title}. Make sure there is at least one valid story for this module.`
);
}
@ -196,7 +196,7 @@ describe('Stories Snapshots', () => {
await new Promise((resolve) => setTimeout(resolve, 1));
// Defines the custom snapshot path location and file name
const customSnapshotPath = `./__snapshots__/${componentName}.spec.js.snap`;
expect(document.body.firstChild).toMatchFileSnapshot(customSnapshotPath);
await expect(document.body.firstChild).toMatchFileSnapshot(customSnapshotPath);
});
});
});
@ -226,7 +226,7 @@ const compose = (entry: StoryFile): ReturnType<typeof composeStories<StoryFile>>
return composeStories(entry);
} catch (e) {
throw new Error(
`There was an issue composing stories for the module: ${JSON.stringify(entry)}, ${e}`,
`There was an issue composing stories for the module: ${JSON.stringify(entry)}, ${e}`
);
}
};
@ -236,7 +236,7 @@ function getAllStoryFiles() {
const storyFiles = Object.entries(
import.meta.glob<StoryFile>('./stories/**/*.(stories|story).@(js|jsx|mjs|ts|tsx)', {
eager: true,
}),
})
);
return storyFiles.map(([filePath, storyFile]) => {
@ -256,7 +256,7 @@ describe('Stories Snapshots', () => {
if (stories.length <= 0) {
throw new Error(
`No stories found for this module: ${title}. Make sure there is at least one valid story for this module.`,
`No stories found for this module: ${title}. Make sure there is at least one valid story for this module.`
);
}
@ -267,7 +267,7 @@ describe('Stories Snapshots', () => {
await new Promise((resolve) => setTimeout(resolve, 1));
// Defines the custom snapshot path location and file name
const customSnapshotPath = `./__snapshots__/${componentName}.spec.ts.snap`;
expect(document.body.firstChild).toMatchFileSnapshot(customSnapshotPath);
await expect(document.body.firstChild).toMatchFileSnapshot(customSnapshotPath);
});
});
});

View File

@ -18,9 +18,9 @@ describe(options.suite, () => {
const snapshotPath = path.join(
storyDir,
options.snapshotsDirName,
`${componentName}${options.snapshotExtension}`,
`${componentName}${options.snapshotExtension}`
);
expect(document.body.firstChild).toMatchFileSnapshot(snapshotPath);
await expect(document.body.firstChild).toMatchFileSnapshot(snapshotPath);
});
});
});