Skip to content

Commit

Permalink
SDKs: add Hydrogen & Remix tests (#3313)
Browse files Browse the repository at this point in the history
## Description
  • Loading branch information
samijaber committed Jun 6, 2024
1 parent b3d0aeb commit 88cf295
Show file tree
Hide file tree
Showing 100 changed files with 10,025 additions and 545 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
'solid-start',
'qwik-city',
'react',
'remix',
'hydrogen',
'next-pages-dir',
'next-app-dir-client',
'next-app-dir',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"devDependencies": {
"@changesets/cli": "^2.27.1",
"dotenv": "^16.0.3",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"octokit": "^2.0.14",
"prettier": "^3.2.5",
"zx": "7.2.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"glob": "^7.2.3",
"glob-promise": "^4.2.2",
"jest": "27.4.7",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"rollup": "^2.38.5",
"rollup-plugin-alias": "^1.5.1",
"rollup-plugin-commonjs": "^10.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0"
"nx": "16.10.0",
"nx-cloud": "16.5.2"
}
}
4 changes: 2 additions & 2 deletions packages/react-tests/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.0.3",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"typescript": "^5"
},
"nx": {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-tests/react-remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"@remix-run/serve": "^1.14.3",
"@sdk/tests": "workspace:*",
"isbot": "^3.6.5",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/react-tests/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"@builder.io/react": "workspace:*",
"@builder.io/widgets": "^1.2.24",
"@sdk/tests": "workspace:*",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"lint-staged": "^7.0.0",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"prettier": "^3.2.5",
"prompt": "^1.0.0",
"react": ">=16.8.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/sdks-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"typescript": "^5.1.6"
},
"dependencies": {
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"traverse": "^0.6.7",
"zod": "^3.20.2"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/sdks-tests/src/e2e-tests/basic-styles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ test.describe('Basic styles', () => {
test('styles should be applied consistently across all SDKs (text and buttons)', async ({
page,
sdk,
packageName,
}) => {
test.fail(checkIsRN(sdk));
test.fail(packageName === 'hydrogen');
await page.goto('/basic-styles');

const button = page.getByRole('button', { name: 'Click Me!' });
Expand Down
3 changes: 2 additions & 1 deletion packages/sdks-tests/src/e2e-tests/blocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
} from '../helpers/index.js';

test.describe('Blocks', () => {
test('Text', async ({ page, sdk }) => {
test('Text', async ({ page, sdk, packageName }) => {
test.fail(packageName === 'hydrogen');
test.fail(excludeRn(sdk));
await page.goto('/text-block');

Expand Down
26 changes: 5 additions & 21 deletions packages/sdks-tests/src/e2e-tests/custom-components.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { expect } from '@playwright/test';
import { excludeTestFor, test } from '../helpers/index.js';
import { test } from '../helpers/index.js';
import { launchEmbedderAndWaitForSdk } from '../helpers/visual-editor.js';

const HELLO_CUSTOM_COMPONENT_LOADED_MESSAGE =
'BUILDER_EVENT: builder.registerComponent Component name: Hello';

test.describe('Custom components', () => {
test('correctly renders custom component', async ({ page, packageName, sdk }) => {
test.skip(
!excludeTestFor(
{
angular: true,
react: true,
},
sdk
)
);
test.skip(packageName === 'next-app-dir-client');
test.skip(!['angular', 'react'].includes(sdk));
test.skip(['next-app-dir-client', 'remix', 'hydrogen'].includes(packageName));
await page.goto('/custom-components');
const helloWorldText = page.locator('text=hello World').first();
await expect(helloWorldText).toBeVisible();
Expand All @@ -28,16 +20,8 @@ test.describe('Custom components', () => {
packageName,
sdk,
}) => {
test.skip(
!excludeTestFor(
{
angular: true,
react: true,
},
sdk
)
);
test.skip(packageName === 'next-app-dir-client');
test.skip(!['angular', 'react'].includes(sdk));
test.skip(['next-app-dir-client', 'remix', 'hydrogen'].includes(packageName));
const customComponentMsgPromise = page.waitForEvent('console', msg =>
msg.text().includes(HELLO_CUSTOM_COMPONENT_LOADED_MESSAGE)
);
Expand Down
3 changes: 3 additions & 0 deletions packages/sdks-tests/src/e2e-tests/editing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const sendContentUpdateMessage = async ({

const editorTests = ({ noTrustedHosts }: { noTrustedHosts: boolean }) => {
test('correctly updates Text block', async ({ page, basePort, packageName }) => {
test.skip(packageName === 'hydrogen');
test.skip(
packageName === 'react-native' ||
packageName === 'next-app-dir' ||
Expand All @@ -59,6 +60,7 @@ const editorTests = ({ noTrustedHosts }: { noTrustedHosts: boolean }) => {
});

test('correctly updates Text block styles', async ({ page, packageName, basePort }) => {
test.skip(packageName === 'hydrogen');
test.skip(
packageName === 'react-native' ||
packageName === 'next-app-dir' ||
Expand Down Expand Up @@ -88,6 +90,7 @@ test.describe('Visual Editing', () => {
basePort,
packageName,
}) => {
test.skip(packageName === 'hydrogen');
test.skip(
packageName === 'react-native' ||
packageName === 'next-app-dir' ||
Expand Down
2 changes: 2 additions & 0 deletions packages/sdks-tests/src/e2e-tests/http-requests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { launchEmbedderAndWaitForSdk } from '../helpers/visual-editor.js';

test.describe('HTTP Requests', () => {
test('call proxy API only once - in page', async ({ page, packageName, sdk }) => {
test.fail(packageName === 'hydrogen');
test.skip(excludeGen1(sdk));
test.fail(packageName === 'next-app-dir', 'editor tests not supported in next-app-dir');
test.fail(excludeTestFor({ angular: true }, sdk), 'Angular Gen2 SDK not implemented.');
Expand Down Expand Up @@ -36,6 +37,7 @@ test.describe('HTTP Requests', () => {
});

test('call proxy API only once - in editor', async ({ page, basePort, packageName, sdk }) => {
test.skip(packageName === 'hydrogen');
test.skip(excludeGen1(sdk));
test.skip(packageName === 'react-native', 'editor tests not supported in react-native');
test.skip(packageName === 'next-app-dir', 'editor tests not supported in next-app-dir');
Expand Down
3 changes: 2 additions & 1 deletion packages/sdks-tests/src/e2e-tests/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test.describe('Hydration', () => {
await findTextInPage({ page, text: 'Stack at tablet' });
});

test('No mismatch on A/B test content', async ({ page }) => {
test('No mismatch on A/B test content', async ({ page, packageName }) => {
test.fail(packageName === 'hydrogen');
await page.goto('/ab-test-interactive');
await page.locator('a').locator('visible=true').first().click({ timeout: 10000 });
await findTextInPage({ page, text: 'Stack at tablet' });
Expand Down
3 changes: 2 additions & 1 deletion packages/sdks-tests/src/e2e-tests/js-code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ test.describe('JS Code', () => {
await expect(menuLocator).toBeVisible();
});

test('code inside Browser.isBrowser should work', async ({ page, sdk }) => {
test('code inside Browser.isBrowser should work', async ({ page, sdk, packageName }) => {
test.fail(packageName === 'hydrogen');
// doesn't work for these as they are SSR and there is no hydration step
// so the code is not run on the client (Builder.isBrowser) block isn't executed
test.fail(excludeTestFor(['vue', 'qwik', 'rsc'], sdk));
Expand Down
33 changes: 20 additions & 13 deletions packages/sdks-tests/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,26 @@ const test = base.extend<TestOptions>({
throw new Error('Failing test due to error in browser: ' + err);
});

context.on('console', msg => {
const originalText = msg.text();
if (checkIfIsHydrationErrorMessage(originalText)) {
throw new Error('Hydration error detected: ' + originalText);
}
});

page.on('console', msg => {
const originalText = msg.text();
if (checkIfIsHydrationErrorMessage(originalText)) {
throw new Error('Hydration error detected: ' + originalText);
}
});
/**
* temporarily disable hydration error checks for hydrogen until we fix them.
*/
const shouldCheckForHydrationError = packageName !== 'hydrogen';

if (shouldCheckForHydrationError) {
context.on('console', msg => {
const originalText = msg.text();
if (checkIfIsHydrationErrorMessage(originalText)) {
throw new Error('Hydration error detected: ' + originalText);
}
});

page.on('console', msg => {
const originalText = msg.text();
if (checkIfIsHydrationErrorMessage(originalText)) {
throw new Error('Hydration error detected: ' + originalText);
}
});
}

await use(page);
},
Expand Down
4 changes: 4 additions & 0 deletions packages/sdks-tests/src/helpers/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const ServerNameEnum = z.enum([
'qwik-city',
'next-pages-dir',
'react',
'remix',
'hydrogen',
'next-app-dir-client',
'next-app-dir',
'vue',
Expand Down Expand Up @@ -51,6 +53,8 @@ export const SDK_MAP: Record<ServerName, Sdk> = {
'qwik-city': 'qwik',
'next-pages-dir': 'react',
react: 'react',
remix: 'react',
hydrogen: 'react',
'next-app-dir-client': 'react',
vue: 'vue',
nuxt: 'vue',
Expand Down
4 changes: 2 additions & 2 deletions packages/sdks/e2e/angular-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"typescript": "~5.1.3"
}
}
4 changes: 2 additions & 2 deletions packages/sdks/e2e/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"nx": "^16.6.0",
"nx-cloud": "^16.2.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"typescript": "~5.1.3"
}
}
5 changes: 5 additions & 0 deletions packages/sdks/e2e/hydrogen/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The variables added in this file are only available locally in MiniOxygen.
# Run `h2 link` to also inject environment variables from your storefront,
# or `h2 env pull` to populate this file.
SESSION_SECRET="foobar"
PUBLIC_STORE_DOMAIN="mock.shop"
5 changes: 5 additions & 0 deletions packages/sdks/e2e/hydrogen/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
node_modules
bin
*.d.ts
dist
19 changes: 19 additions & 0 deletions packages/sdks/e2e/hydrogen/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @type {import("@types/eslint").Linter.BaseConfig}
*/
module.exports = {
root: true,
extends: [
'@remix-run/eslint-config',
// 'plugin:hydrogen/recommended',
'plugin:hydrogen/typescript',
],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/naming-convention': 'off',
'hydrogen/prefer-image-component': 'off',
'no-useless-escape': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'no-case-declarations': 'off',
},
};
9 changes: 9 additions & 0 deletions packages/sdks/e2e/hydrogen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
/.cache
/build
/dist
/public/build
/.mf
.shopify

!.env
12 changes: 12 additions & 0 deletions packages/sdks/e2e/hydrogen/.graphqlrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
projects:
default:
schema: 'node_modules/@shopify/hydrogen/storefront.schema.json'
documents:
- '!*.d.ts'
- '*.{ts,tsx,js,jsx}'
- 'app/**/*.{ts,tsx,js,jsx}'
- '!app/graphql/**/*.{ts,tsx,js,jsx}'
customer-account:
schema: 'node_modules/@shopify/hydrogen/customer-account.schema.json'
documents:
- 'app/graphql/customer-account/**/*.{ts,tsx,js,jsx}'

0 comments on commit 88cf295

Please sign in to comment.