Skip to content

Commit

Permalink
Merge pull request #138 from withastro/main
Browse files Browse the repository at this point in the history
A200
  • Loading branch information
akshit20421 authored Feb 18, 2024
2 parents 10ac6e4 + ddf0f92 commit 7760af8
Show file tree
Hide file tree
Showing 258 changed files with 336 additions and 597 deletions.
2 changes: 1 addition & 1 deletion packages/astro-rss/test/pagesGlobToRssItems.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('pagesGlobToRssItems', () => {
},
];

assert.deepStrictEqual(
assert.deepEqual(
items.sort((a, b) => a.pubDate - b.pubDate),
expected
);
Expand Down
18 changes: 9 additions & 9 deletions packages/astro-rss/test/rss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function assertXmlDeepEqual(a, b) {
const parsedA = parseXmlString(a);
const parsedB = parseXmlString(b);

assert.strictEqual(parsedA.err, null);
assert.strictEqual(parsedB.err, null);
assert.deepStrictEqual(parsedA.result, parsedB.result);
assert.equal(parsedA.err, null);
assert.equal(parsedB.err, null);
assert.deepEqual(parsedA.result, parsedB.result);
}

describe('rss', () => {
Expand All @@ -58,7 +58,7 @@ describe('rss', () => {
assertXmlDeepEqual(str, validXmlResult);

const contentType = response.headers.get('Content-Type');
assert.strictEqual(contentType, 'application/xml');
assert.equal(contentType, 'application/xml');
});

it('should be the same string as getRssString', async () => {
Expand All @@ -73,7 +73,7 @@ describe('rss', () => {
const str1 = await response.text();
const str2 = await getRssString(options);

assert.strictEqual(str1, str2);
assert.equal(str1, str2);
});
});

Expand Down Expand Up @@ -223,8 +223,8 @@ describe('getRssString', () => {
link: phpFeedItem.link,
});

assert.strictEqual(res.success, false);
assert.strictEqual(res.error.issues[0].path[0], 'pubDate');
assert.equal(res.success, false);
assert.equal(res.error.issues[0].path[0], 'pubDate');
});

it('should be extendable', () => {
Expand All @@ -236,7 +236,7 @@ describe('getRssString', () => {
} catch (e) {
error = e.message;
}
assert.strictEqual(error, null);
assert.equal(error, null);
});

it('should not fail when an enclosure has a length of 0', async () => {
Expand Down Expand Up @@ -264,6 +264,6 @@ describe('getRssString', () => {
error = e.message;
}

assert.strictEqual(error, null);
assert.equal(error, null);
});
});
5 changes: 1 addition & 4 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@
"dev": "astro-scripts dev --copy-wasm --prebuild \"src/runtime/server/astro-island.ts\" --prebuild \"src/runtime/client/{idle,load,media,only,visible}.ts\" \"src/**/*.{ts,js}\"",
"postbuild": "astro-scripts copy \"src/**/*.astro\" && astro-scripts copy \"src/**/*.wasm\"",
"test": "pnpm run test:node",
"test:match": "mocha ./test/*.test.js --timeout 30000 -g",
"test:e2e": "playwright test",
"test:e2e:match": "playwright test -g",
"test:node": "astro-scripts test \"test/**/*.nodetest.js\""
"test:node": "astro-scripts test \"test/**/*.test.js\""
},
"dependencies": {
"@astrojs/compiler": "^2.5.3",
Expand Down Expand Up @@ -212,11 +211,9 @@
"@types/unist": "^3.0.2",
"@types/yargs-parser": "^21.0.3",
"astro-scripts": "workspace:*",
"chai": "^4.3.7",
"cheerio": "1.0.0-rc.12",
"eol": "^0.9.1",
"memfs": "^4.6.0",
"mocha": "^10.2.0",
"node-mocks-http": "^1.13.0",
"parse-srcset": "^1.0.2",
"rehype-autolink-headings": "^7.1.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/src/content/types-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export async function createContentTypesGenerator({
}
const collectionInfo = collectionEntryMap[collectionKey];
if (collectionInfo.type === 'content') {
viteServer.ws.send({
viteServer.hot.send({
type: 'error',
err: new AstroError({
...AstroErrorData.MixedContentDataCollectionError,
Expand Down Expand Up @@ -212,7 +212,7 @@ export async function createContentTypesGenerator({
}
const collectionInfo = collectionEntryMap[collectionKey];
if (collectionInfo.type === 'data') {
viteServer.ws.send({
viteServer.hot.send({
type: 'error',
err: new AstroError({
...AstroErrorData.MixedContentDataCollectionError,
Expand Down Expand Up @@ -359,7 +359,7 @@ async function writeContentFiles({
typeTemplateContent: string;
contentEntryTypes: Pick<ContentEntryType, 'contentModuleTypes'>[];
contentConfig?: ContentConfig;
viteServer: Pick<ViteDevServer, 'ws'>;
viteServer: Pick<ViteDevServer, 'hot'>;
}) {
let contentTypesStr = '';
let dataTypesStr = '';
Expand All @@ -374,7 +374,7 @@ async function writeContentFiles({
collection.type !== 'unknown' &&
collection.type !== collectionConfig.type
) {
viteServer.ws.send({
viteServer.hot.send({
type: 'error',
err: new AstroError({
...AstroErrorData.ContentCollectionTypeMismatchError,
Expand All @@ -387,7 +387,7 @@ async function writeContentFiles({
collection.type === 'data'
? "Try adding `type: 'data'` to your collection config."
: undefined,
location: { file: '' /** required for error overlay `ws` messages */ },
location: { file: '' /** required for error overlay `hot` messages */ },
}) as any,
});
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/dev/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function restartContainer(container: Container): Promise<Container
);
}
// Inform connected clients of the config error
container.viteServer.ws.send({
container.viteServer.hot.send({
type: 'error',
err: {
message: error.message,
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/core/module-loader/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader {
}
});

const _wsSend = viteServer.ws.send;
viteServer.ws.send = function (...args: any) {
const _wsSend = viteServer.hot.send;
viteServer.hot.send = function (...args: any) {
// If the tsconfig changed, Vite will trigger a reload as it invalidates the module.
// However in Astro, the whole server is restarted when the tsconfig changes. If we
// do a restart and reload at the same time, the browser will refetch and the server
Expand Down Expand Up @@ -75,13 +75,13 @@ export function createViteLoader(viteServer: vite.ViteDevServer): ModuleLoader {
return viteServer.ssrFixStacktrace(err);
},
clientReload() {
viteServer.ws.send({
viteServer.hot.send({
type: 'full-reload',
path: '*',
});
},
webSocketSend(msg) {
return viteServer.ws.send(msg);
return viteServer.hot.send(msg);
},
isHttps() {
return !!viteServer.config.server.https;
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ export async function syncInternal(
)
);

// Patch `ws.send` to bubble up error events
// `ws.on('error')` does not fire for some reason
const wsSend = tempViteServer.ws.send;
tempViteServer.ws.send = (payload: HMRPayload) => {
// Patch `hot.send` to bubble up error events
// `hot.on('error')` does not fire for some reason
const hotSend = tempViteServer.hot.send;
tempViteServer.hot.send = (payload: HMRPayload) => {
if (payload.type === 'error') {
throw payload.err;
}
return wsSend(payload);
return hotSend(payload);
};

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function handleHotUpdate(
ctx.server.moduleGraph.invalidateModule(mod);
}
}
ctx.server.ws.send({ type: 'full-reload', path: '*' });
ctx.server.hot.send({ type: 'full-reload', path: '*' });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ export default function astroDevToolbar({ settings, logger }: AstroPluginOptions
}
},
configureServer(server) {
server.ws.on('astro:devtoolbar:error:load', (args) => {
server.hot.on('astro:devtoolbar:error:load', (args) => {
logger.error(
'toolbar',
`Failed to load dev toolbar app from ${args.entrypoint}: ${args.error}`
);
});

server.ws.on('astro:devtoolbar:error:init', (args) => {
server.hot.on('astro:devtoolbar:error:init', (args) => {
logger.error(
'toolbar',
`Failed to initialize dev toolbar app ${args.app.name} (${args.app.id}):\n${args.error}`
);
});

server.ws.on('astro:devtoolbar:app:toggled', (args) => {
server.hot.on('astro:devtoolbar:app:toggled', (args) => {
// Debounce telemetry to avoid recording events when the user is rapidly toggling apps for debugging
clearTimeout(telemetryTimeout);
telemetryTimeout = setTimeout(() => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('Astro basic build', () => {
const $ = cheerio.load(html);

// will be 1 if element rendered correctly
assert.strictEqual($('#one').length, 1);
assert.equal($('#one').length, 1);
});

it('supports special chars in filename', async () => {
Expand All @@ -108,45 +108,42 @@ describe('Astro basic build', () => {
it('renders the components top-down', async () => {
const html = await fixture.readFile('/order/index.html');
const $ = cheerio.load(html);
assert.strictEqual($('#rendered-order').text(), 'Rendered order: A, B');
assert.equal($('#rendered-order').text(), 'Rendered order: A, B');
});

it('renders markdown in utf-8 by default', async () => {
const html = await fixture.readFile('/chinese-encoding-md/index.html');
const $ = cheerio.load(html);
assert.strictEqual($('h1').text(), '我的第一篇博客文章');
assert.equal($('h1').text(), '我的第一篇博客文章');
});

it('renders MDX in utf-8 by default', async () => {
const html = await fixture.readFile('/chinese-encoding-mdx/index.html');
const $ = cheerio.load(html);
assert.strictEqual($('h1').text(), '我的第一篇博客文章');
assert.equal($('h1').text(), '我的第一篇博客文章');
});

it('Supports void elements whose name is a string (#2062)', async () => {
const html = await fixture.readFile('/input/index.html');
const $ = cheerio.load(html);

// <Input />
assert.strictEqual($('body > :nth-child(1)').prop('outerHTML'), '<input>');
assert.equal($('body > :nth-child(1)').prop('outerHTML'), '<input>');

// <Input type="password" />
assert.strictEqual($('body > :nth-child(2)').prop('outerHTML'), '<input type="password">');
assert.equal($('body > :nth-child(2)').prop('outerHTML'), '<input type="password">');

// <Input type="text" />
assert.strictEqual($('body > :nth-child(3)').prop('outerHTML'), '<input type="text">');
assert.equal($('body > :nth-child(3)').prop('outerHTML'), '<input type="text">');

// <Input type="select"><option>option</option></Input>
assert.strictEqual(
assert.equal(
$('body > :nth-child(4)').prop('outerHTML'),
'<select><option>option</option></select>'
);

// <Input type="textarea">textarea</Input>
assert.strictEqual(
$('body > :nth-child(5)').prop('outerHTML'),
'<textarea>textarea</textarea>'
);
assert.equal($('body > :nth-child(5)').prop('outerHTML'), '<textarea>textarea</textarea>');
});

it('Generates pages that end with .mjs', async () => {
Expand All @@ -159,18 +156,18 @@ describe('Astro basic build', () => {
it('allows file:// urls as module specifiers', async () => {
const html = await fixture.readFile('/fileurl/index.html');
const $ = cheerio.load(html);
assert.strictEqual($('h1').text(), 'WORKS');
assert.equal($('h1').text(), 'WORKS');
});

describe('preview', () => {
it('returns 200 for valid URLs', async () => {
const result = await fixture.fetch('/');
assert.strictEqual(result.status, 200);
assert.equal(result.status, 200);
});

it('returns 404 for invalid URLs', async () => {
const result = await fixture.fetch('/bad-url');
assert.strictEqual(result.status, 404);
assert.equal(result.status, 404);
});
});
});
Expand All @@ -193,7 +190,7 @@ describe('Astro basic development', () => {

it('Renders markdown in utf-8 by default', async () => {
const res = await fixture.fetch('/chinese-encoding-md');
assert.strictEqual(res.status, 200);
assert.equal(res.status, 200);
const html = await res.text();
const $ = cheerio.load(html);
assert.equal($('h1').text(), '我的第一篇博客文章');
Expand All @@ -205,7 +202,7 @@ describe('Astro basic development', () => {

it('Renders MDX in utf-8 by default', async () => {
const res = await fixture.fetch('/chinese-encoding-mdx');
assert.strictEqual(res.status, 200);
assert.equal(res.status, 200);
const html = await res.text();
const $ = cheerio.load(html);
assert.equal($('h1').text(), '我的第一篇博客文章');
Expand Down
Loading

0 comments on commit 7760af8

Please sign in to comment.