aboutsummaryrefslogtreecommitdiff
path: root/packages/astro/test/astro-sync.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/astro/test/astro-sync.test.js')
-rw-r--r--packages/astro/test/astro-sync.test.js98
1 files changed, 44 insertions, 54 deletions
diff --git a/packages/astro/test/astro-sync.test.js b/packages/astro/test/astro-sync.test.js
index ce1345322..e9ab90cf7 100644
--- a/packages/astro/test/astro-sync.test.js
+++ b/packages/astro/test/astro-sync.test.js
@@ -24,10 +24,6 @@ const createFixture = () => {
return astroFixture.config;
},
clean() {
- const envPath = new URL('env.d.ts', astroFixture.config.srcDir);
- if (fs.existsSync(envPath)) {
- fs.unlinkSync(new URL('env.d.ts', astroFixture.config.srcDir));
- }
fs.rmSync(new URL('./.astro/', astroFixture.config.root), { force: true, recursive: true });
},
async whenSyncing() {
@@ -80,6 +76,14 @@ const createFixture = () => {
},
/**
* @param {string} path
+ * @param {string} content
+ * @param {string | undefined} error
+ */
+ thenFileContentShouldNotInclude(path, content, error = undefined) {
+ assert.equal(writtenFiles[getExpectedPath(path)].includes(content), false, error);
+ },
+ /**
+ * @param {string} path
*/
thenFileShouldBeValidTypescript(path) {
try {
@@ -108,40 +112,15 @@ describe('astro sync', () => {
fixture = createFixture();
});
- describe('References', () => {
- it('Writes `src/env.d.ts` if none exists', async () => {
- await fixture.load('./fixtures/astro-basic/');
- fixture.clean();
- await fixture.whenSyncing();
- fixture.thenFileShouldExist('src/env.d.ts');
- fixture.thenFileContentShouldInclude(
- 'src/env.d.ts',
- `/// <reference path="../.astro/types.d.ts" />`,
- );
- });
-
- it('Updates `src/env.d.ts` if one exists', async () => {
- const config = await fixture.load('./fixtures/astro-basic/');
- fixture.clean();
- fs.writeFileSync(new URL('./env.d.ts', config.srcDir), '// whatever', 'utf-8');
- await fixture.whenSyncing();
- fixture.thenFileShouldExist('src/env.d.ts');
- fixture.thenFileContentShouldInclude(
- 'src/env.d.ts',
- `/// <reference path="../.astro/types.d.ts" />`,
- );
- });
-
- it('Writes `src/types.d.ts`', async () => {
- await fixture.load('./fixtures/astro-basic/');
- fixture.clean();
- await fixture.whenSyncing();
- fixture.thenFileShouldExist('.astro/types.d.ts');
- fixture.thenFileContentShouldInclude(
- '.astro/types.d.ts',
- `/// <reference types="astro/client" />`,
- );
- });
+ it('Writes `.astro/types.d.ts`', async () => {
+ await fixture.load('./fixtures/astro-basic/');
+ fixture.clean();
+ await fixture.whenSyncing();
+ fixture.thenFileShouldExist('.astro/types.d.ts');
+ fixture.thenFileContentShouldInclude(
+ '.astro/types.d.ts',
+ `/// <reference types="astro/client" />`,
+ );
});
describe('Content collections', () => {
@@ -152,15 +131,15 @@ describe('astro sync', () => {
fixture.thenFileShouldExist('.astro/types.d.ts');
fixture.thenFileContentShouldInclude(
'.astro/types.d.ts',
- `/// <reference path="astro/content.d.ts" />`,
+ `/// <reference path="content.d.ts" />`,
);
- fixture.thenFileShouldExist('.astro/astro/content.d.ts');
+ fixture.thenFileShouldExist('.astro/content.d.ts');
fixture.thenFileContentShouldInclude(
- '.astro/astro/content.d.ts',
+ '.astro/content.d.ts',
`declare module 'astro:content' {`,
'Types file does not include `astro:content` module declaration',
);
- fixture.thenFileShouldBeValidTypescript('.astro/astro/content.d.ts');
+ fixture.thenFileShouldBeValidTypescript('.astro/content.d.ts');
});
it('Writes types for empty collections', async () => {
@@ -168,27 +147,38 @@ describe('astro sync', () => {
fixture.clean();
await fixture.whenSyncing();
fixture.thenFileContentShouldInclude(
- '.astro/astro/content.d.ts',
+ '.astro/content.d.ts',
`"blog": Record<string, {
id: string;
+ render(): Render[".md"];
slug: string;
body: string;
collection: "blog";
data: InferEntrySchema<"blog">;
- render(): Render[".md"];
-}>;`,
+ rendered?: RenderedContent;
+ filePath?: string;`,
'Types file does not include empty collection type',
);
fixture.thenFileContentShouldInclude(
- '.astro/astro/content.d.ts',
+ '.astro/content.d.ts',
`"blogMeta": Record<string, {
id: string;
+ body?: string;
collection: "blogMeta";
data: InferEntrySchema<"blogMeta">;
+ rendered?: RenderedContent;
+ filePath?: string;
}>;`,
'Types file does not include empty collection type',
);
});
+
+ it('does not write individual types for entries when emulating legacy collections', async () => {
+ await fixture.load('./fixtures/content-collections/');
+ fixture.clean();
+ await fixture.whenSyncing();
+ fixture.thenFileContentShouldNotInclude('.astro/content.d.ts', 'id: "one.md"');
+ });
});
describe('astro:env', () => {
@@ -199,11 +189,11 @@ describe('astro sync', () => {
fixture.thenFileShouldExist('.astro/types.d.ts');
fixture.thenFileContentShouldInclude(
'.astro/types.d.ts',
- `/// <reference path="astro/env.d.ts" />`,
+ `/// <reference path="env.d.ts" />`,
);
- fixture.thenFileShouldExist('.astro/astro/env.d.ts');
+ fixture.thenFileShouldExist('.astro/env.d.ts');
fixture.thenFileContentShouldInclude(
- '.astro/astro/env.d.ts',
+ '.astro/env.d.ts',
`declare module 'astro:env/client' {`,
'Types file does not include `astro:env` module declaration',
);
@@ -219,7 +209,7 @@ describe('astro sync', () => {
assert.fail();
}
});
- it('Does not throw if a virtual module is imported in content/config.ts', async () => {
+ it('Does not throw if a virtual module is imported in content.config.ts', async () => {
try {
await fixture.load('./fixtures/astro-env-content-collections/');
fixture.clean();
@@ -239,15 +229,15 @@ describe('astro sync', () => {
fixture.thenFileShouldExist('.astro/types.d.ts');
fixture.thenFileContentShouldInclude(
'.astro/types.d.ts',
- `/// <reference path="astro/actions.d.ts" />`,
+ `/// <reference path="actions.d.ts" />`,
);
- fixture.thenFileShouldExist('.astro/astro/actions.d.ts');
+ fixture.thenFileShouldExist('.astro/actions.d.ts');
fixture.thenFileContentShouldInclude(
- '.astro/astro/actions.d.ts',
+ '.astro/actions.d.ts',
`declare module "astro:actions" {`,
'Types file does not include `astro:actions` module declaration',
);
- fixture.thenFileShouldBeValidTypescript('.astro/astro/actions.d.ts');
+ fixture.thenFileShouldBeValidTypescript('.astro/actions.d.ts');
});
});
});