forked from sveltejs/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic smoke tests for adapter-node
* verify the server starts * verify it can serve a 404 --- Additional changes: - change server.js to be a function that creates the server but does not start it. - update build rules to build from a new index.js file that builds and starts the app - update the package type to module to enable esm imports - expose a way to call into server with a render function - add a guard clause around no static asset folder existing. - change imports in adapter-node to work with import and not require BUG sveltejs#639
- Loading branch information
Showing
7 changed files
with
106 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createServer } from './server'; | ||
/*eslint import/no-unresolved: [2, { ignore: ['\.\/app\.js$'] }]*/ | ||
import * as app from './app.js'; | ||
|
||
const { PORT = 3000 } = process.env; // TODO configure via svelte.config.js | ||
|
||
const instance = createServer({ render: app.render }).listen(PORT, (err) => { | ||
if (err) { | ||
console.log('error', err); | ||
} else { | ||
console.log(`Listening on port ${PORT}`); | ||
} | ||
}); | ||
|
||
export { instance }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { test } from 'uvu'; | ||
import { createServer } from '../src/server.js'; | ||
import * as assert from 'uvu/assert'; | ||
import fetch from 'node-fetch'; | ||
|
||
const { PORT = 3000 } = process.env; | ||
|
||
function startServer() { | ||
const server = createServer({ render: () => {} }); | ||
return new Promise((fulfil, reject) => { | ||
server.listen(PORT, (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
fulfil(server); | ||
}); | ||
}); | ||
} | ||
|
||
test('starts a server', async () => { | ||
const server = await startServer(); | ||
assert.ok('server started'); | ||
server.server.close(); | ||
}); | ||
|
||
test('serves a 404', async () => { | ||
const server = await startServer(); | ||
const res = await fetch(`http://localhost:${PORT}/nothing`); | ||
assert.equal(res.status, 404); | ||
server.server.close(); | ||
}); | ||
|
||
test.run(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.