Skip to content

Commit

Permalink
fix(#180): Prepend Server.init before calling Server.respond (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
pham authored Sep 2, 2022
1 parent 2cd9be4 commit 5c937c9
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ jobs:
params:
- {
test_dir: "functions_single_site",
validation_app_dir: "public/_app/immutable/pages/index.svelte-*.js",
validation_app_dir: "public/_app/immutable/components/pages/_page.svelte-*.js",
validation_compute_dir: "functions/sveltekit/index.js",
nested_dir: ".",
}
- {
test_dir: "nested_app_dirs",
validation_app_dir: "public/_app/immutable/pages/index.svelte-*.js",
validation_app_dir: "public/_app/immutable/components/pages/_page.svelte-*.js",
validation_compute_dir: "functions/sveltekit/index.js",
nested_dir: "app",
}
- {
test_dir: "run_service_id",
validation_app_dir: "public/_app/immutable/pages/index.svelte-*.js",
validation_app_dir: "public/_app/immutable/components/pages/_page.svelte-*.js",
validation_compute_dir: "functions/cloudrun/index.js",
nested_dir: ".",
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"esbuild": "^0.15.2"
},
"peerDependencies": {
"@sveltejs/kit": "^1.0.0-next.405"
"@sveltejs/kit": "^1.0.0-next.443"
},
"devDependencies": {
"@sveltejs/kit": "^1.0.0-next.405",
"@sveltejs/kit": "^1.0.0-next.443",
"@types/express": "^4.17.13",
"@types/node": "^18.7.3",
"ava": "^4.3.1",
Expand Down
94 changes: 88 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/files/entry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'process';
import {Server} from 'SERVER';
import {manifest} from 'MANIFEST';
import {toSvelteKitRequest} from './firebase-to-svelte-kit.js';
Expand All @@ -16,6 +17,10 @@ const server = new Server(manifest);
* @returns {Promise<void>}
*/
export default async function svelteKit(request, response) {
await server.init({
env: process.env,
});

const rendered = await server.respond(toSvelteKitRequest(request));
const body = await rendered.text();

Expand Down
13 changes: 8 additions & 5 deletions tests/end-to-end/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -u
IFS=$'\n\t'

# Execute end-to-end tests of the SvelteKit Todo template app built with
# the svelte-adapter-firebase adapter hosted on the Cloud Function using
# the svelte-adapter-firebase adapter hosted on the Cloud Function using
# the Firebase Emulator in CI
#
# Curl API and assert response payload
Expand All @@ -26,7 +26,7 @@ echo "TEST_DIR: ${TEST_DIR}"
echo "PWD: ${PWD}"

echo "${INDICATOR}Install svelte-adapter-firebase ${SCRIPT_PATH}/../../ deps"
npm install
npm install

echo "${INDICATOR}init SvelteKit Todos app"
yes "" | "$(npm init svelte@next "${TEST_DIR}")"
Expand Down Expand Up @@ -68,24 +68,27 @@ RESULT="$(curl -L localhost:${PORT}/about)"

if [[ "${RESULT}" != *"${EXPECTED_SUBSTRING}"* ]]; then
echo "Failed testing localhost:${PORT}/about"
echo -e "Expect --> ${EXPECTED_SUBSTRING}\nGot -->\n${RESULT}"
exit 1
fi

echo "${INDICATOR}Test GET SSR route '/'"
EXPECTED_SUBSTRING="<h2>try editing <strong>src/routes/index.svelte</strong></h2>"
EXPECTED_SUBSTRING="<h2>try editing <strong"
RESULT="$(curl -L localhost:${PORT}/)"

if [[ "${RESULT}" != *"${EXPECTED_SUBSTRING}"* ]]; then
echo "${INDICATOR}Failed testing localhost:${PORT}/"
echo -e "Expect --> ${EXPECTED_SUBSTRING}\nGot -->\n${RESULT}"
exit 1
fi

echo "${INDICATOR}Test GET SSR route '/todos'"
EXPECTED_SUBSTRING="<h1>Todos</h1>"
EXPECTED_SUBSTRING='<h1>Todos</h1>'
RESULT="$(curl -L localhost:${PORT}/todos)"

if [[ "${RESULT}" != *"${EXPECTED_SUBSTRING}"* ]]; then
echo "${INDICATOR}Failed testing localhost:${PORT}/todos/"
echo -e "Expect --> ${EXPECTED_SUBSTRING}\nGot -->\n${RESULT}"
exit 1
fi

Expand All @@ -107,9 +110,9 @@ RESULT="$(curl -X POST "http://localhost:${PORT}/todos" \
-H "Sec-Fetch-Mode: cors" \
-H "Sec-Fetch-Site: same-origin" \
-H 'Sec-GPC: 1' --data-binary $'-----------------------------349341627025106406523834848301\r\nContent-Disposition: form-data; name="text"\r\n\r\nasdf\r\n-----------------------------349341627025106406523834848301--\r\n')"
echo "$RESULT"
if [[ "${RESULT}" != *"${EXPECTED_SUBSTRING}"* ]]; then
echo "${INDICATOR}Failed POSTing to localhost:${PORT}/todos"
echo -e "Expect --> ${EXPECTED_SUBSTRING}\nGot -->\n${RESULT}"
exit 1
fi

Expand Down

0 comments on commit 5c937c9

Please sign in to comment.