Add HMR port script when needed (#375)
* Always add HMR port script when HMR is enabled * Add it only if there are client side components * Fix the test * Add a test where HMR port not set * Upgrade snowpack version * Fix snowpack semver
This commit is contained in:
parent
a660e49f80
commit
afa09ee9dc
7 changed files with 43 additions and 10 deletions
|
@ -87,7 +87,7 @@
|
|||
"sass": "^1.32.13",
|
||||
"shorthash": "^0.0.2",
|
||||
"slash": "^4.0.0",
|
||||
"snowpack": "^3.5.6",
|
||||
"snowpack": "^3.5.7",
|
||||
"source-map-support": "^0.5.19",
|
||||
"string-width": "^5.0.0",
|
||||
"tiny-glob": "^0.2.8",
|
||||
|
|
|
@ -11,7 +11,7 @@ export default function (opts: TransformOptions): Transformer {
|
|||
visitors: {
|
||||
html: {
|
||||
InlineComponent: {
|
||||
enter(node, parent) {
|
||||
enter(node) {
|
||||
const [name, kind] = node.name.split(':');
|
||||
if (kind && !hasComponents) {
|
||||
hasComponents = true;
|
||||
|
@ -20,7 +20,6 @@ export default function (opts: TransformOptions): Transformer {
|
|||
},
|
||||
Element: {
|
||||
enter(node) {
|
||||
if (!hasComponents) return;
|
||||
switch (node.name) {
|
||||
case 'head': {
|
||||
head = node;
|
||||
|
@ -56,7 +55,7 @@ export default function (opts: TransformOptions): Transformer {
|
|||
});
|
||||
}
|
||||
|
||||
if (isHmrEnabled) {
|
||||
if (isHmrEnabled && hasComponents) {
|
||||
const { hmrPort } = opts.compileOptions;
|
||||
children.push(
|
||||
{
|
||||
|
|
|
@ -5,7 +5,11 @@ import { setup } from './helpers.js';
|
|||
|
||||
const Basics = suite('Basic test');
|
||||
|
||||
setup(Basics, './fixtures/astro-basic');
|
||||
setup(Basics, './fixtures/astro-basic', {
|
||||
runtimeOptions: {
|
||||
mode: 'development'
|
||||
}
|
||||
});
|
||||
|
||||
Basics('Can load page', async ({ runtime }) => {
|
||||
const result = await runtime.load('/');
|
||||
|
@ -16,4 +20,16 @@ Basics('Can load page', async ({ runtime }) => {
|
|||
assert.equal($('h1').text(), 'Hello world!');
|
||||
});
|
||||
|
||||
Basics('Sets the HMR port when dynamic components used', async ({ runtime }) => {
|
||||
const result = await runtime.load('/client');
|
||||
const html = result.contents;
|
||||
assert.ok(/HMR_WEBSOCKET_URL/.test(html), 'Sets the websocket port');
|
||||
});
|
||||
|
||||
Basics('Does not set the HMR port when no dynamic component used', async ({ runtime }) => {
|
||||
const result = await runtime.load('/');
|
||||
const html = result.contents;
|
||||
assert.ok(!/HMR_WEBSOCKET_URL/.test(html), 'Does not set the websocket port');
|
||||
});
|
||||
|
||||
Basics.run();
|
||||
|
|
5
packages/astro/test/fixtures/astro-basic/src/components/Tour.jsx
vendored
Normal file
5
packages/astro/test/fixtures/astro-basic/src/components/Tour.jsx
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { h } from 'preact';
|
||||
|
||||
export default function() {
|
||||
return <div>Testing</div>
|
||||
}
|
12
packages/astro/test/fixtures/astro-basic/src/pages/client.astro
vendored
Normal file
12
packages/astro/test/fixtures/astro-basic/src/pages/client.astro
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
import Tour from '../components/Tour.jsx';
|
||||
---
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Stuff</title>
|
||||
</head>
|
||||
<body>
|
||||
<Tour:load />
|
||||
</body>
|
||||
</html>
|
|
@ -11,7 +11,7 @@ const MAX_TEST_TIME = 10000; // max time an individual test may take
|
|||
const MAX_SHUTDOWN_TIME = 3000; // max time shutdown() may take
|
||||
|
||||
/** setup fixtures for tests */
|
||||
export function setup(Suite, fixturePath) {
|
||||
export function setup(Suite, fixturePath, { runtimeOptions = {} } = {}) {
|
||||
let runtime;
|
||||
const timers = {};
|
||||
|
||||
|
@ -24,6 +24,7 @@ export function setup(Suite, fixturePath) {
|
|||
|
||||
runtime = await createRuntime(astroConfig, {
|
||||
logging: { level: 'error', dest: process.stderr },
|
||||
...runtimeOptions
|
||||
});
|
||||
|
||||
context.runtime = runtime;
|
||||
|
|
|
@ -8938,10 +8938,10 @@ smartwrap@^1.2.3:
|
|||
wcwidth "^1.0.1"
|
||||
yargs "^15.1.0"
|
||||
|
||||
snowpack@^3.5.6:
|
||||
version "3.5.6"
|
||||
resolved "https://registry.yarnpkg.com/snowpack/-/snowpack-3.5.6.tgz#79f8699e4248e19f67ec50433e50072bb2e69e89"
|
||||
integrity sha512-R9uqattPhS2j1zaOFgwl7i54rFTtxxk4kmKmqJBRwD+9YggUulGm7O7YRXaMMjtmi69czK7jxbtZs1Up/xA+1A==
|
||||
snowpack@^3.5.7:
|
||||
version "3.5.7"
|
||||
resolved "https://registry.yarnpkg.com/snowpack/-/snowpack-3.5.7.tgz#1d56a273c97e6f8fe23800f4d3c641eefb65f356"
|
||||
integrity sha512-mMdbG9vSs7JL69/Zk2VtpduBnbfzCCCXvhJeX4GzPg4aYyKtfs0s6MA5VoQbN9HL6lZpKRy/knaigKcC4E29GA==
|
||||
dependencies:
|
||||
cli-spinners "^2.5.0"
|
||||
default-browser-id "^2.0.0"
|
||||
|
|
Loading…
Reference in a new issue