Skip to content

Commit

Permalink
Fix dotenv issues, so now server is actually starting with test suite…
Browse files Browse the repository at this point in the history
… on correct port
  • Loading branch information
MaddyGuthridge committed Jul 31, 2024
1 parent 9e049d4 commit 0b16c7b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
'^\\$lib(.*)$': '<rootDir>/src/lib$1',
'^\\$types(.*)$': '<rootDir>/src/types$1',
'^\\$components(.*)$': '<rootDir>/src/components$1',
'^\\$api(.*)$': '<rootDir>/tests/api$1',
'^\\$app(.*)$': [
'<rootDir>/.svelte-kit/dev/runtime/app$1',
'<rootDir>/.svelte-kit/build/runtime/app$1'
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@typescript-eslint/parser": "^7.0.0",
"asciinema-player": "github:MaddyGuthridge/asciinema-player",
"babel-jest": "^29.7.0",
"cross-fetch": "^4.0.0",
"eslint": "^8.56.0",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-svelte": "^2.35.1",
Expand Down
5 changes: 3 additions & 2 deletions tests/api/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import dotenv from 'dotenv';
import ApiError from './ApiError';
import fetch from 'cross-fetch';

export type HttpVerb = 'GET' | 'POST' | 'PUT' | 'DELETE';

dotenv.config();

export const PORT = process.env.PORT as string;
export const IP = process.env.IP as string;
export const URL = `http://${IP}:${PORT}`;
export const HOST = process.env.HOST as string;
export const URL = `http://${HOST}:${PORT}`;

/**
* Fetch some data from the backend
Expand Down
8 changes: 5 additions & 3 deletions tests/setup/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { setup } from 'jest-dev-server';
import dotenv from 'dotenv';
dotenv.config();

module.exports = async () => {
console.log('\nStarting server...');
const command = 'npm run dev -- --host localhost --port 5173';
const command = `npm run dev -- --host ${process.env.HOST} --port ${process.env.PORT}`;
globalThis.servers = await setup({
command,
launchTimeout: 50 * 1000,
// Server started manually in another terminal? Simply run the test.
// Used port actions are ['ask', 'error', 'ignore', 'kill'].
usedPortAction: 'ignore',
port: 5173,
host: 'localhost',
port: parseInt(process.env.PORT as string),
host: process.env.HOST,
debug: true,
waitOnScheme: {
delay: 1000,
Expand Down
7 changes: 7 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import dotenv from 'dotenv';
dotenv.config();

export default defineConfig({
server: {
port: parseInt(process.env.PORT as string),
strictPort: true,
host: process.env.HOST,
},
plugins: [
sveltekit()
],
Expand Down

0 comments on commit 0b16c7b

Please sign in to comment.