Less verbose HMR script (#457)
* Less verbose HMR script * push changeset
This commit is contained in:
parent
54c291efa0
commit
251b0b5c06
4 changed files with 11 additions and 6 deletions
5
.changeset/breezy-carrots-clap.md
Normal file
5
.changeset/breezy-carrots-clap.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Less verbose HMR script
|
|
@ -62,7 +62,7 @@ export default function (opts: TransformOptions): Transformer {
|
||||||
type: 'Element',
|
type: 'Element',
|
||||||
name: 'script',
|
name: 'script',
|
||||||
attributes: [],
|
attributes: [],
|
||||||
children: [{ type: 'Text', data: `window.HMR_WEBSOCKET_URL = window.HMR_WEBSOCKET_URL || 'ws://localhost:${hmrPort}';`, start: 0, end: 0 }],
|
children: [{ type: 'Text', data: `window.HMR_WEBSOCKET_PORT = ${hmrPort};`, start: 0, end: 0 }],
|
||||||
start: 0,
|
start: 0,
|
||||||
end: 0,
|
end: 0,
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,13 +23,13 @@ Basics('Can load page', async ({ runtime }) => {
|
||||||
Basics('Sets the HMR port when dynamic components used', async ({ runtime }) => {
|
Basics('Sets the HMR port when dynamic components used', async ({ runtime }) => {
|
||||||
const result = await runtime.load('/client');
|
const result = await runtime.load('/client');
|
||||||
const html = result.contents;
|
const html = result.contents;
|
||||||
assert.ok(/HMR_WEBSOCKET_URL/.test(html), 'Sets the websocket port');
|
assert.ok(/HMR_WEBSOCKET_PORT/.test(html), 'Sets the websocket port');
|
||||||
});
|
});
|
||||||
|
|
||||||
Basics('Does not set the HMR port when no dynamic component used', async ({ runtime }) => {
|
Basics('Does not set the HMR port when no dynamic component used', async ({ runtime }) => {
|
||||||
const result = await runtime.load('/');
|
const result = await runtime.load('/');
|
||||||
const html = result.contents;
|
const html = result.contents;
|
||||||
assert.ok(!/HMR_WEBSOCKET_URL/.test(html), 'Does not set the websocket port');
|
assert.ok(!/HMR_WEBSOCKET_PORT/.test(html), 'Does not set the websocket port');
|
||||||
});
|
});
|
||||||
|
|
||||||
Basics('Correctly serializes boolean attributes', async ({ runtime }) => {
|
Basics('Correctly serializes boolean attributes', async ({ runtime }) => {
|
||||||
|
|
|
@ -16,7 +16,7 @@ HMR('Honors the user provided port', async ({ runtime }) => {
|
||||||
if (result.error) throw new Error(result.error);
|
if (result.error) throw new Error(result.error);
|
||||||
|
|
||||||
const html = result.contents;
|
const html = result.contents;
|
||||||
assert.ok(/window\.HMR_WEBSOCKET_URL = window\.HMR_WEBSOCKET_URL || 'ws:\/\/localhost:5555'/.test(html), "Uses the user's websocket port");
|
assert.ok(/window\.HMR_WEBSOCKET_PORT = 5555/.test(html), "Uses the user's websocket port");
|
||||||
});
|
});
|
||||||
|
|
||||||
HMR('Does not override script added by the user', async ({ runtime }) => {
|
HMR('Does not override script added by the user', async ({ runtime }) => {
|
||||||
|
@ -25,8 +25,8 @@ HMR('Does not override script added by the user', async ({ runtime }) => {
|
||||||
|
|
||||||
const html = result.contents;
|
const html = result.contents;
|
||||||
|
|
||||||
assert.ok(!/window\.HMR_WEBSOCKET_URL = 'ws:\/\/localhost:3333'/.test(html), 'Users script included');
|
assert.ok(/window\.HMR_WEBSOCKET_URL = 'wss:\/\/example.com:3333'/.test(html), "User's script included");
|
||||||
assert.ok(/window\.HMR_WEBSOCKET_URL = window\.HMR_WEBSOCKET_URL || 'ws:\/\/localhost:5555'/.test(html), 'Our script defers to the port already being set');
|
assert.ok(/window\.HMR_WEBSOCKET_PORT = 5555/.test(html), 'Ignored when window.HMR_WEBSOCKET_URL set');
|
||||||
});
|
});
|
||||||
|
|
||||||
HMR.run();
|
HMR.run();
|
||||||
|
|
Loading…
Add table
Reference in a new issue