Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Enable more tests with new compiler changes #1558

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"test": "mocha --parallel --timeout 15000"
},
"dependencies": {
"@astrojs/compiler": "^0.1.14",
"@astrojs/compiler": "^0.1.15",
"@astrojs/markdown-remark": "^0.3.1",
"@astrojs/renderer-preact": "^0.2.2",
"@astrojs/renderer-react": "^0.2.1",
Expand All @@ -56,16 +56,16 @@
"connect": "^3.7.0",
"del": "^6.0.0",
"es-module-lexer": "^0.7.1",
"esbuild": "^0.12.28",
"esbuild": "^0.13.6",
"estree-util-value-to-estree": "^1.2.0",
"fast-xml-parser": "^3.19.0",
"html-entities": "^2.3.2",
"kleur": "^4.1.4",
"mime": "^2.5.2",
"morphdom": "^2.6.1",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.5",
"path-to-regexp": "^6.2.0",
"sass": "^1.42.0",
"sass": "^1.43.2",
"semver": "^7.3.5",
"send": "^0.17.1",
"shiki": "^0.9.10",
Expand All @@ -78,7 +78,7 @@
"strip-ansi": "^7.0.1",
"supports-esm": "^1.0.0",
"tiny-glob": "^0.2.8",
"vite": "^2.6.5",
"vite": "^2.6.7",
"yargs-parser": "^20.2.9",
"zod": "^3.8.1"
},
Expand All @@ -93,7 +93,7 @@
"@types/yargs-parser": "^20.2.1",
"chai": "^4.3.4",
"cheerio": "^1.0.0-rc.10",
"mocha": "^9.1.1"
"mocha": "^9.1.2"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0",
Expand Down
8 changes: 1 addition & 7 deletions packages/astro/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,7 @@ class AstroBuilder {
},
target: 'es2020', // must match an esbuild target
},
plugins: [
rollupPluginHTML({
input,
extractAssets: false,
}) as any, // CI fix: ignore typing of this plugin
...(viteConfig.plugins || []),
],
plugins: [rollupPluginHTML({ input, extractAssets: false }), ...(viteConfig.plugins || [])],
publicDir: viteConfig.publicDir,
root: viteConfig.root,
server: viteConfig.server,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/build/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function profileJS({ cwd, entryHTML }: { cwd: URL; entryHTML?: URL
const relPath = url.pathname.replace(cwd.pathname, '');
if (sizes[relPath]) return;
try {
let code = url.protocol === 'file:' ? await fs.promises.readFile(url, 'utf8') : await fetch(url).then((body) => body.text());
let code = url.protocol === 'file:' ? await fs.promises.readFile(url, 'utf8') : await fetch(url.href).then((body) => body.text());
sizes[relPath] = Buffer.byteLength(code);
const staticImports = eslexer.parse(code)[0].filter(({ d }) => {
if (!visitedEntry) return true; // if we’re on the entry file, count async imports, too
Expand Down
27 changes: 13 additions & 14 deletions packages/astro/src/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,27 @@ interface ExtractedHydration {
directive: string;
value: string;
componentUrl: string;
componentExport: { value: string; };
componentExport: { value: string };
} | null;
props: Record<string | number, any>
props: Record<string | number, any>;
}

function extractHydrationDirectives(inputProps: Record<string | number, any>): ExtractedHydration {
let extracted: ExtractedHydration = {
hydration: null,
props: {}
props: {},
};
for (const [key, value] of Object.entries(inputProps)) {
if (key.startsWith('client:')) {
if(!extracted.hydration) {
if (!extracted.hydration) {
extracted.hydration = {
directive: '',
value: '',
componentUrl: '',
componentExport: { value: '' }
componentExport: { value: '' },
};
}
switch(key) {
switch (key) {
case 'client:component-path': {
extracted.hydration.componentUrl = value;
break;
Expand Down Expand Up @@ -212,8 +212,8 @@ export async function renderComponent(result: SSRResult, displayName: string, Co
}
}

if(renderer === null) {
if(typeof Component === 'string') {
if (renderer === null) {
if (typeof Component === 'string') {
html = await renderAstroComponent(await render`<${Component}${spreadAttributes(props)}>${children}</${Component}>`);
} else {
throw new Error(`Astro is unable to render ${metadata.displayName}!\nIs there a renderer to handle this type of component defined in your Astro config?`);
Expand Down Expand Up @@ -251,10 +251,12 @@ function createFetchContentFn(url: URL) {
if (!mod.frontmatter) {
return;
}
const urlSpec = new URL(spec, url).pathname.replace(/[\\/\\\\]/, '/');
return {
content: mod.metadata,
metadata: mod.frontmatter,
file: new URL(spec, url),
url: urlSpec.includes('/pages/') && urlSpec.replace(/^.*\/pages\//, '/').replace(/\.md$/, ''),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-adding URL for markdown files. We need this for RSS, and this just re-adds what was here before.

All other changes here are just prettier reformatting.

};
})
.filter(Boolean);
Expand All @@ -264,18 +266,15 @@ function createFetchContentFn(url: URL) {

export function createAstro(fileURLStr: string, site: string): TopLevelAstro {
const url = pathToFileURL(fileURLStr);
const fetchContent = createFetchContentFn(url) as unknown as TopLevelAstro['fetchContent'];
const fetchContent = createFetchContentFn(url) as unknown as TopLevelAstro['fetchContent'];
return {
// TODO I think this is no longer needed.
isPage: false,
site: new URL(site),
fetchContent,
resolve(...segments) {
return segments.reduce(
(u, segment) => new URL(segment, u),
url
).pathname
}
return segments.reduce((u, segment) => new URL(segment, u), url).pathname;
},
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/runtime/vite/plugin-astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export default function astro({ config, devServer }: AstroPluginOptions): Plugin
site: config.buildOptions.site,
sourcefile: id,
sourcemap: 'both',
internalURL: 'astro/internal'
internalURL: 'astro/internal',
});
// 2. Compile `.ts` to `.js`
const { code, map } = await esbuild.transform(tsResult.code, { loader: 'ts', sourcemap: 'external', sourcefile: id });

return {
code,
map,
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/test/astro-assets.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* UNCOMMENT: add support for automatic <img> and srcset in build

import { expect } from 'chai';
import { loadFixture } from './test-utils';
import { loadFixture } from './test-utils.js';

let fixture;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/astro-doctype.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* UNCOMMENT: fix layout bug
* UNCOMMENT: compiler doesn’t insert <!doctype>
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
Expand Down
5 changes: 0 additions & 5 deletions packages/astro/test/astro-expr.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/**
* UNCOMMENT: @astrojs/compiler transform error
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
Expand Down Expand Up @@ -102,6 +100,3 @@ describe('Expressions', () => {
expect($('#frag-undefined')).to.have.lengthOf(0);
});
});
*/

it.skip('is skipped', () => {});
2 changes: 1 addition & 1 deletion packages/astro/test/astro-external-files.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* UNCOMMENT: fix Vite error for external files
* UNCOMMENT: add support for smarter "external" scripts in Rollup
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All currently-skipped tests updated with more helpful TODOs (almost all tests are closer to passing! 🎉 so even though we didn’t enable all of the tests, all failing tests have fewer blockers now)

import { expect } from 'chai';
import { loadFixture } from './test-utils.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/astro-get-static-paths.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* UNCOMMENT: add getStaticPaths()
* UNCOMMENT: fix "Error: can only be called once!"
import { expect } from 'chai';
import { loadFixture } from './test-utils';

Expand Down
3 changes: 1 addition & 2 deletions packages/astro/test/astro-global.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ before(async () => {
await fixture.build();
});


describe('Astro.*', () => {
it('Astro.request.url', async () => {
const html = await fixture.readFile('/index.html');
Expand Down Expand Up @@ -55,4 +54,4 @@ describe('Astro.*', () => {
expect($('img').attr('src')).to.equal('/src/images/penguin.png');
expect($('#inner-child img').attr('src')).to.equal('/src/components/nested/images/penguin.png');
});
});
});
2 changes: 1 addition & 1 deletion packages/astro/test/astro-pagination.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* UNCOMMENT: add Astro.fetchContent()
* UNCOMMENT: there’s a bug with Canonical URLs
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
Expand Down
15 changes: 7 additions & 8 deletions packages/astro/test/astro-rss.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/**
* UNCOMMENT: add getStaticPaths() support
import { expect } from 'chai';
import { loadFixture } from './test-utils.js';

Expand All @@ -9,18 +7,19 @@ before(async () => {
fixture = await loadFixture({
projectRoot: './fixtures/astro-rss/',
buildOptions: {
site: 'https://mysite.dev',
site: 'https://astro.build/',
sitemap: true,
},
});
await fixture.build();
});

describe.skip('RSS Generation', () => {
describe('RSS Generation', () => {
it('generates RSS correctly', async () => {
const rss = await fixture.readFile('/custom/feed.xml');
expect(rss).to.be(''); // TODO: inline snapshot
expect(rss).to.equal(
`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title><![CDATA[MF Doomcast]]></title><description><![CDATA[The podcast about the things you find on a picnic, or at a picnic table]]></description><link>https://astro.build/custom/feed.xml</link><language>en-us</language><itunes:author>MF Doom</itunes:author><item><title><![CDATA[Fazers]]></title><link>https://astro.build/episode/fazers/</link><description><![CDATA[Rhapsody ranked Take Me to Your Leader 17th on its list “Hip-Hop’s Best Albums of the Decade”]]></description><pubDate>Thu, 03 Jul 2003 00:00:00 GMT</pubDate><itunes:episodeType>music</itunes:episodeType><itunes:duration>197</itunes:duration><itunes:explicit>true</itunes:explicit></item><item><title><![CDATA[Rap Snitch Knishes (feat. Mr. Fantastik)]]></title><link>https://astro.build/episode/rap-snitch-knishes/</link><description><![CDATA[Complex named this song the “22nd funniest rap song of all time.”]]></description><pubDate>Tue, 16 Nov 2004 00:00:00 GMT</pubDate><itunes:episodeType>music</itunes:episodeType><itunes:duration>172</itunes:duration><itunes:explicit>true</itunes:explicit></item><item><title><![CDATA[Rhymes Like Dimes (feat. Cucumber Slice)]]></title><link>https://astro.build/episode/rhymes-like-dimes/</link><description><![CDATA[Operation: Doomsday has been heralded as an underground classic that established MF Doom's rank within the underground hip-hop scene during the early to mid-2000s.
]]></description><pubDate>Tue, 19 Oct 1999 00:00:00 GMT</pubDate><itunes:episodeType>music</itunes:episodeType><itunes:duration>259</itunes:duration><itunes:explicit>true</itunes:explicit></item></channel></rss>`
);
});
});
*/

it.skip('is skipped', () => {});
17 changes: 10 additions & 7 deletions packages/astro/test/astro-sitemap.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/**
* UNCOMMENT: add getStaticPaths() support
import { expect } from 'chai';
import { loadFixture } from './test-utils.js';

let fixture;

before(async () => {
fixture = await loadFixture({ projectRoot: './fixtures/astro-rss/' });
fixture = await loadFixture({
projectRoot: './fixtures/astro-rss/',
buildOptions: {
site: 'https://astro.build/',
sitemap: true,
},
});
await fixture.build();
});

describe('Sitemap Generation', () => {
it('Generates Sitemap correctly', async () => {
let sitemap = await fixture.readFile('/sitemap.xml');
expect(sitemap).to.be(''); // TODO: inline snapshot
expect(sitemap).to.equal(
`<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://astro.build/404/index.html</loc></url><url><loc>https://astro.build/episode/fazers/index.html</loc></url><url><loc>https://astro.build/episode/rap-snitch-knishes/index.html</loc></url><url><loc>https://astro.build/episode/rhymes-like-dimes/index.html</loc></url><url><loc>https://astro.build/episodes/index.html</loc></url></urlset>\n`
);
});
});
*/

it.skip('is skipped', () => {});
2 changes: 1 addition & 1 deletion packages/astro/test/astro-styles-ssr.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* UNCOMMENT: fix frontmatter import hoisting
* UNCOMMENT: Add styles support
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/builtins.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* UNCOMMENT: separate this fixture into two
* UNCOMMENT: Fix "Unexpected "\x00" bug
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/custom-elements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ describe('Custom Elements', () => {
// test 1: Element rendered
expect($('client-only-element')).to.have.lengthOf(1);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
import Child from '../components/Child.astro';
---
<html>
<head>
Expand All @@ -9,7 +8,5 @@ import Child from '../components/Child.astro';
<body>
<div id="pathname">{Astro.request.url.pathname}</div>
<a id="site" href={Astro.site}>Home</a>

<Child />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

export function getStaticPaths({paginate, rss}) {
const episodes = Astro.fetchContent('../episode/*.md').sort((a, b) => new Date(b.pubDate) - new Date(a.pubDate));
rss({
Expand All @@ -11,14 +10,14 @@ export function getStaticPaths({paginate, rss}) {
},
customData: `<language>en-us</language>` +
`<itunes:author>MF Doom</itunes:author>`,
items: episodes.map((item) => ({
title: item.title,
link: item.url,
description: item.description,
pubDate: item.pubDate + 'Z',
customData: `<itunes:episodeType>${item.type}</itunes:episodeType>` +
`<itunes:duration>${item.duration}</itunes:duration>` +
`<itunes:explicit>${item.explicit || false}</itunes:explicit>`,
items: episodes.map(({ metadata, url }) => ({
title: metadata.title,
link: url,
description: metadata.description,
pubDate: metadata.pubDate + 'Z',
customData: `<itunes:episodeType>${metadata.type}</itunes:episodeType>` +
`<itunes:duration>${metadata.duration}</itunes:duration>` +
`<itunes:explicit>${metadata.explicit || false}</itunes:explicit>`,
})),
dest: '/custom/feed.xml',
});
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/fixtures/builtins/src/pages/bare.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import fs from 'fs';
<body>
<h1>Test</h1>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion packages/astro/test/lit-element.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* UNCOMMENT: fix "window is not defined" Vite error
* UNCOMMENT: fix Vite SSR import of lit-element (TODO: update render API)
import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
Expand Down
Loading