Skip to content

Commit

Permalink
Add e2e for plugin routes
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Aug 2, 2022
1 parent 4d7f64a commit 7f27109
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/playground/server-components/hydrogen.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {defineConfig, CookieSessionStorage} from '@shopify/hydrogen/config';
import myTestPlugin from './my-test-plugin/plugin.js';

export default defineConfig({
shopify: {
Expand All @@ -16,4 +17,5 @@ export default defineConfig({
debug() {},
},
serverErrorPage: '/src/500Error.tsx',
plugins: [myTestPlugin({})],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "my-test-plugin",
"private": "true",
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {definePlugin} from '@shopify/hydrogen/config';

export default definePlugin(() => ({
name: 'my-test-plugin',
url: import.meta.url,
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function MyPlugin() {
return <h1>Hello My Plugin</h1>;
}

export function api() {
return new Response('Plugin OK');
}
12 changes: 12 additions & 0 deletions packages/playground/server-components/tests/e2e-test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,4 +894,16 @@ export default async function testCases({
expect(await page.textContent('h2')).toContain('itBroke is not defined');
});
});

describe('Hydrogen Plugins', () => {
it('imports plugin routes', async () => {
const pluginRoute = getServerUrl() + '/my-plugin';
await page.goto(pluginRoute);
expect(await page.textContent('h1')).toContain('Hello My Plugin');

expect(await (await fetch(pluginRoute, {method: 'POST'})).text()).toEqual(
'Plugin OK'
);
});
});
}

0 comments on commit 7f27109

Please sign in to comment.