Skip to content

Commit

Permalink
chore(cut-short): Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni committed Sep 21, 2024
1 parent e0d26fa commit 60dffce
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/cut-short/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"debug": "catalog:"
},
"devDependencies": {
"@inox-tools/astro-tests": "workspace:",
"@types/node": "catalog:",
"@vitest/coverage-v8": "catalog:",
"@vitest/ui": "catalog:",
Expand Down
25 changes: 25 additions & 0 deletions packages/cut-short/tests/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { loadFixture, type TestApp } from '@inox-tools/astro-tests/astroFixture';
import testAdapter from '@inox-tools/astro-tests/testAdapter';
import { beforeAll, expect, test } from 'vitest';

const fixture = await loadFixture({
root: './fixture/basic',
output: 'server',
adapter: testAdapter(),
});

let app: TestApp;

beforeAll(async () => {
await fixture.build({});
app = await fixture.loadTestAdapterApp();
});

test('ending request on page frontmatter', async () => {
const res = await app.render(new Request('https://example.com/'));

expect(res.headers.get('Content-Type')).toEqual('application/json');

const content = await res.json();
expect(content).toEqual({ cutShort: true });
});
1 change: 0 additions & 1 deletion packages/cut-short/tests/env.d.ts

This file was deleted.

6 changes: 6 additions & 0 deletions packages/cut-short/tests/fixture/basic/astro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import cutShort from '@inox-tools/cut-short';

export default defineConfig({
integrations: [cutShort()],
});
9 changes: 9 additions & 0 deletions packages/cut-short/tests/fixture/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@cut-short/basic",
"private": true,
"type": "module",
"dependencies": {
"@inox-tools/cut-short": "workspace:",
"astro": "catalog:"
}
}
7 changes: 7 additions & 0 deletions packages/cut-short/tests/fixture/basic/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
import { endRequest } from '@it-astro:cut-short';
endRequest(Response.json({ cutShort: true }));
---

<div>You shouldn't see this</div>
3 changes: 3 additions & 0 deletions packages/cut-short/virtual.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
declare module '@it-astro:cut-short' {
import type { MaybeThunk } from '@inox-tools/utils/types';

export const endRequest: (withResponse: MaybeThunk<Response>) => never;
}
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 60dffce

Please sign in to comment.