@@ -30,8 +30,8 @@ The minimum Vite config file should contain:
3030
3131``` js
3232 test: {
33- globalSetup: [ // This script will start Mongo
34- ' node_modules/@adaptivestone/framework/tests/globalSetupVitest' ,
33+ globalSetup: [ // This script will start Mongo (DIST in important there)
34+ ' node_modules/@adaptivestone/framework/dist/ tests/globalSetupVitest' ,
3535 ],
3636 setupFiles: [
3737 ' ./src/tests/setup.js' , // This is a local config file (see below)
@@ -198,36 +198,44 @@ jobs:
198198 token : ${{ secrets.CODECOV_TOKEN }}
199199` ` `
200200
201+ ## Server isntance access
202+
203+ Possible that in testing you will need to have low level access to server itself. We have helper there too
204+
205+ ` ` ` js
206+ import { serverInstance } from "@adaptivestone/framework/tests/testHelpers.ts";
207+ ```
208+
201209## HTTP Endpoint Testing
202210
203- The framework provides a special function ` global.server.testingGetUrl ` to detect the testing URL .
211+ The framework provides a special function ` getTestServerURL ` to help you construct full url for testing .
204212
205213``` js
206- const url = global.server.testingGetUrl("/auth");
214+ import { getTestServerURL } from " @adaptivestone/framework/tests/testHelpers.js" ;
215+ const url = getTestServerURL (" /auth" );
207216```
208217
209218Full example:
210219
211220``` js
221+ import { getTestServerURL } from " @adaptivestone/framework/tests/testHelpers.ts" ;
222+
212223describe (" module" , () => {
213224 describe (" function" , () => {
214225 it (" test" , async () => {
215226 expect .assertions (1 );
216- const { status } = await fetch(
217- global.server.testingGetUrl("/some/endpoint"),
218- {
219- method: "POST",
220- headers: {
221- "Content-type": "application/json",
222- Authorization: global.User.token.token,
223- },
224- body: JSON.stringify({
225- // request object
226- oneData: 1,
227- secondDate: 2,
228- }),
229- }
230- ).catch(() => {});
227+ const { status } = await fetch (getTestServerURL (" /some/endpoint" ), {
228+ method: " POST" ,
229+ headers: {
230+ " Content-type" : " application/json" ,
231+ Authorization: global .User .token .token ,
232+ },
233+ body: JSON .stringify ({
234+ // request object
235+ oneData: 1 ,
236+ secondDate: 2 ,
237+ }),
238+ }).catch (() => {});
231239 expect (status).toBe (400 );
232240 });
233241 });
0 commit comments