1- import { expect } from 'chai' ;
1+ import assert from 'node:assert/strict' ;
2+ import { describe , it , beforeEach , afterEach } from 'node:test' ;
23import path from 'path' ;
34
4- import { createTestServer } from '../helpers.js ' ;
5- import { DevServer } from '../../src /server/DevServer.js' ;
5+ import { createTestServer , expectIncludes , expectNotIncludes } from '../helpers.ts ' ;
6+ import type { DevServer } from '../../dist /server/DevServer.js' ;
67
78describe ( 'history api fallback middleware' , ( ) => {
89 describe ( 'index in root' , ( ) => {
@@ -11,7 +12,7 @@ describe('history api fallback middleware', () => {
1112
1213 beforeEach ( async ( ) => {
1314 ( { host, server } = await createTestServer ( {
14- appIndex : path . resolve ( __dirname , '..' , 'fixtures' , 'basic' , 'index.html' ) ,
15+ appIndex : path . resolve ( import . meta . dirname , '..' , 'fixtures' , 'basic' , 'index.html' ) ,
1516 } ) ) ;
1617 } ) ;
1718
@@ -23,41 +24,41 @@ describe('history api fallback middleware', () => {
2324 const response = await fetch ( `${ host } /index.html` ) ;
2425 const responseText = await response . text ( ) ;
2526
26- expect ( response . status ) . to . equal ( 200 ) ;
27- expect ( responseText ) . to . include ( '<title>My app</title>' ) ;
27+ assert . equal ( response . status , 200 ) ;
28+ expectIncludes ( responseText , '<title>My app</title>' ) ;
2829 } ) ;
2930
3031 it ( 'returns the fallback index.html for non-file requests' , async ( ) => {
3132 const response = await fetch ( `${ host } /foo` ) ;
3233 const responseText = await response . text ( ) ;
3334
34- expect ( response . status ) . to . equal ( 200 ) ;
35- expect ( responseText ) . to . include ( '<title>My app</title>' ) ;
35+ assert . equal ( response . status , 200 ) ;
36+ expectIncludes ( responseText , '<title>My app</title>' ) ;
3637 } ) ;
3738
3839 it ( 'returns the fallback index.html for file requests with multiple segments' , async ( ) => {
3940 const response = await fetch ( `${ host } /foo/bar/baz` ) ;
4041 const responseText = await response . text ( ) ;
4142
42- expect ( response . status ) . to . equal ( 200 ) ;
43- expect ( responseText ) . to . include ( '<title>My app</title>' ) ;
43+ assert . equal ( response . status , 200 ) ;
44+ expectIncludes ( responseText , '<title>My app</title>' ) ;
4445 } ) ;
4546
4647 it ( 'does not return index.html for file requests' , async ( ) => {
4748 const response = await fetch ( `${ host } /src/hello-world.txt` ) ;
4849 const responseText = await response . text ( ) ;
4950
50- expect ( response . status ) . to . equal ( 200 ) ;
51- expect ( responseText ) . to . include ( 'Hello world!' ) ;
52- expect ( responseText ) . to . not . include ( '<title>My app</title>' ) ;
51+ assert . equal ( response . status , 200 ) ;
52+ expectIncludes ( responseText , 'Hello world!' ) ;
53+ expectNotIncludes ( responseText , '<title>My app</title>' ) ;
5354 } ) ;
5455
5556 it ( 'does return index.html for requests that have url parameters with . characters (issue 1059)' , async ( ) => {
5657 const response = await fetch ( `${ host } /text-files/foo/bar/?baz=open.wc` ) ;
5758 const responseText = await response . text ( ) ;
5859
59- expect ( response . status ) . to . equal ( 200 ) ;
60- expect ( responseText ) . to . include ( '<title>My app</title>' ) ;
60+ assert . equal ( response . status , 200 ) ;
61+ expectIncludes ( responseText , '<title>My app</title>' ) ;
6162 } ) ;
6263 } ) ;
6364
@@ -67,7 +68,7 @@ describe('history api fallback middleware', () => {
6768
6869 beforeEach ( async ( ) => {
6970 ( { host, server } = await createTestServer ( {
70- appIndex : path . resolve ( __dirname , '..' , 'fixtures' , 'basic' , 'src' , 'index.html' ) ,
71+ appIndex : path . resolve ( import . meta . dirname , '..' , 'fixtures' , 'basic' , 'src' , 'index.html' ) ,
7172 } ) ) ;
7273 } ) ;
7374
@@ -79,40 +80,40 @@ describe('history api fallback middleware', () => {
7980 const response = await fetch ( `${ host } /src/index.html` ) ;
8081 const responseText = await response . text ( ) ;
8182
82- expect ( response . status ) . to . equal ( 200 ) ;
83- expect ( responseText ) . to . include ( '<title>My app 2</title>' ) ;
83+ assert . equal ( response . status , 200 ) ;
84+ expectIncludes ( responseText , '<title>My app 2</title>' ) ;
8485 } ) ;
8586
8687 it ( 'returns the fallback index.html for non-file requests' , async ( ) => {
8788 const response = await fetch ( `${ host } /src/foo` ) ;
8889 const responseText = await response . text ( ) ;
8990
90- expect ( response . status ) . to . equal ( 200 ) ;
91- expect ( responseText ) . to . include ( '<title>My app 2</title>' ) ;
91+ assert . equal ( response . status , 200 ) ;
92+ expectIncludes ( responseText , '<title>My app 2</title>' ) ;
9293 } ) ;
9394
9495 it ( 'returns the fallback index.html for file requests with multiple segments' , async ( ) => {
9596 const response = await fetch ( `${ host } /src/foo/bar/baz` ) ;
9697 const responseText = await response . text ( ) ;
9798
98- expect ( response . status ) . to . equal ( 200 ) ;
99- expect ( responseText ) . to . include ( '<title>My app 2</title>' ) ;
99+ assert . equal ( response . status , 200 ) ;
100+ expectIncludes ( responseText , '<title>My app 2</title>' ) ;
100101 } ) ;
101102
102103 it ( 'does not return the index.html for requests outside the index root' , async ( ) => {
103104 const response = await fetch ( `${ host } /foo` ) ;
104105 const responseText = await response . text ( ) ;
105106
106- expect ( response . status ) . to . equal ( 404 ) ;
107- expect ( responseText ) . to . not . include ( '<title>My app 2</title>' ) ;
107+ assert . equal ( response . status , 404 ) ;
108+ expectNotIncludes ( responseText , '<title>My app 2</title>' ) ;
108109 } ) ;
109110
110111 it ( 'does return index.html for requests that have url parameters with . characters (issue 1059)' , async ( ) => {
111112 const response = await fetch ( `${ host } /src/foo/bar/?baz=open.wc` ) ;
112113 const responseText = await response . text ( ) ;
113114
114- expect ( response . status ) . to . equal ( 200 ) ;
115- expect ( responseText ) . to . include ( '<title>My app 2</title>' ) ;
115+ assert . equal ( response . status , 200 ) ;
116+ expectIncludes ( responseText , '<title>My app 2</title>' ) ;
116117 } ) ;
117118 } ) ;
118119} ) ;
0 commit comments