Skip to content

Commit

Permalink
only assert on major versions in resolved react e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Mar 22, 2024
1 parent 031f47a commit 1e5a57c
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions code/e2e-tests/addon-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ test.describe('addon-docs', () => {
});

test('should resolve react to the correct version', async ({ page }) => {
// Arrange - Navigate to MDX docs and setup expectations
// Arrange - Navigate to MDX docs
const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docs2/resolvedreact', 'mdx', 'docs');
const root = sbPage.previewRoot();

// Arrange - Setup expectations
let expectedReactVersionRange = /^18/;
if (
templateName.includes('preact') ||
Expand All @@ -211,19 +212,13 @@ test.describe('addon-docs', () => {

// Assert - The versions are in the expected range
await expect(mdxReactVersion).toHaveText(expectedReactVersionRange);

const actualReactVersion = (await mdxReactVersion.textContent())!;
// Assert - The versions are all the same
// react-dom has a bug in its production build, reporting version 18.2.0-next-9e3b772b8-20220608 even though version 18.2.0 is installed.
await expect(mdxReactDomVersion).toHaveText(new RegExp(`^${actualReactVersion}`));
await expect(componentReactVersion).toHaveText(expectedReactVersionRange);
await expect(mdxReactDomVersion).toHaveText(expectedReactVersionRange);
await expect(componentReactDomVersion).toHaveText(expectedReactVersionRange);
if (!templateName.includes('preact')) {
// preact/compat alias doesn't have a version export in react-dom/server
await expect(mdxReactDomServerVersion).toHaveText(actualReactVersion);
}
await expect(componentReactVersion).toHaveText(actualReactVersion);
await expect(componentReactDomVersion).toHaveText(new RegExp(`^${actualReactVersion}`));
if (!templateName.includes('preact')) {
await expect(componentReactDomServerVersion).toHaveText(actualReactVersion);
await expect(mdxReactDomServerVersion).toHaveText(expectedReactVersionRange);
await expect(componentReactDomServerVersion).toHaveText(expectedReactVersionRange);
}

// Arrange - Navigate to autodocs
Expand All @@ -234,11 +229,13 @@ test.describe('addon-docs', () => {
const autodocsReactDomVersion = await root.getByTestId('react-dom');
const autodocsReactDomServerVersion = await root.getByTestId('react-dom-server');

await expect(autodocsReactVersion).toHaveText(actualReactVersion);
await expect(autodocsReactDomVersion).toHaveText(new RegExp(`^${actualReactVersion}`));
// Assert - The versions are in the expected range
await expect(autodocsReactVersion).toHaveText(expectedReactVersionRange);
await expect(autodocsReactDomVersion).toHaveText(expectedReactVersionRange);
if (!templateName.includes('preact')) {
await expect(autodocsReactDomServerVersion).toHaveText(actualReactVersion);
await expect(autodocsReactDomServerVersion).toHaveText(expectedReactVersionRange);
}

// Arrange - Navigate to story
await sbPage.navigateToStory('addons/docs/docs2/resolvedreact', 'story');

Expand All @@ -247,10 +244,11 @@ test.describe('addon-docs', () => {
const storyReactDomVersion = await root.getByTestId('react-dom');
const storyReactDomServerVersion = await root.getByTestId('react-dom-server');

await expect(storyReactVersion).toHaveText(actualReactVersion);
await expect(storyReactDomVersion).toHaveText(new RegExp(`^${actualReactVersion}`));
// Assert - The versions are in the expected range
await expect(storyReactVersion).toHaveText(expectedReactVersionRange);
await expect(storyReactDomVersion).toHaveText(expectedReactVersionRange);
if (!templateName.includes('preact')) {
await expect(storyReactDomServerVersion).toHaveText(actualReactVersion);
await expect(storyReactDomServerVersion).toHaveText(expectedReactVersionRange);
}
});

Expand Down

0 comments on commit 1e5a57c

Please sign in to comment.