1+ import { describe , it } from 'node:test' ;
2+ import assert from 'node:assert/strict' ;
13import path from 'path' ;
2- import { fileURLToPath } from 'url' ;
34import { runTests } from '@web/test-runner-core/test-helpers' ;
45import { chromeLauncher } from '@web/test-runner-chrome' ;
56import { nodeResolvePlugin } from '@web/dev-server' ;
67
7- import { moduleMockingPlugin } from '../src/moduleMockingPlugin.js' ;
8- import { expect } from 'chai' ;
9-
10- const dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
11-
12- describe ( 'moduleMockingPlugin' , function test ( ) {
13- this . timeout ( 20000 ) ;
8+ import { moduleMockingPlugin } from '../dist/moduleMockingPlugin.js' ;
149
10+ describe ( 'moduleMockingPlugin' , { timeout : 20000 } , ( ) => {
1511 it ( 'can intercept server relative modules' , async ( ) => {
1612 await runTests ( {
17- files : [ path . join ( dirname , 'fixtures' , 'server-relative' , 'browser-test.js' ) ] ,
13+ files : [ path . join ( import . meta . dirname , 'fixtures' , 'server-relative' , 'browser-test.js' ) ] ,
1814 browsers : [ chromeLauncher ( ) ] ,
1915 plugins : [ moduleMockingPlugin ( ) , nodeResolvePlugin ( '' , false , { } ) ] ,
2016 } ) ;
2117 } ) ;
2218
2319 it ( 'can intercept bare modules' , async ( ) => {
24- const rootDir = path . resolve ( dirname , 'fixtures' , 'bare' , 'fixture' ) ;
20+ const rootDir = path . resolve ( import . meta . dirname , 'fixtures' , 'bare' , 'fixture' ) ;
2521 // Define the bare module as duped to force nodeResolve to use the passed rootDir instead of the cwd
2622 const dedupe = ( importee : string ) => importee === 'time-library/hour' ;
2723
2824 await runTests ( {
29- files : [ path . join ( dirname , 'fixtures' , 'bare' , 'browser-test.js' ) ] ,
25+ files : [ path . join ( import . meta . dirname , 'fixtures' , 'bare' , 'browser-test.js' ) ] ,
3026 browsers : [ chromeLauncher ( ) ] ,
3127 plugins : [ moduleMockingPlugin ( ) , nodeResolvePlugin ( rootDir , false , { dedupe } ) ] ,
3228 } ) ;
@@ -35,56 +31,57 @@ describe('moduleMockingPlugin', function test() {
3531 it ( 'throws when trying to intercept without the plugin' , async ( ) => {
3632 const { sessions } = await runTests (
3733 {
38- files : [ path . join ( dirname , 'fixtures' , 'server-relative' , 'browser-test.js' ) ] ,
34+ files : [ path . join ( import . meta . dirname , 'fixtures' , 'server-relative' , 'browser-test.js' ) ] ,
3935 browsers : [ chromeLauncher ( ) ] ,
4036 plugins : [ nodeResolvePlugin ( '' , false , { } ) ] ,
4137 } ,
4238 [ ] ,
4339 { allowFailure : true , reportErrors : false } ,
4440 ) ;
4541
46- expect ( sessions . length ) . to . equal ( 1 ) ;
47- expect ( sessions [ 0 ] . passed ) . to . equal ( false ) ;
48- expect ( sessions [ 0 ] . errors . length ) . to . equal ( 1 ) ;
49- expect ( sessions [ 0 ] . logs [ 0 ] [ 0 ] ) . to . match ( / E r r o r : M o d u l e i n t e r c e p t i o n i s n o t a c t i v e ./ ) ;
50- expect ( sessions [ 0 ] . errors [ 0 ] . message ) . to . match ( / C o u l d n o t i m p o r t y o u r t e s t m o d u l e ./ ) ;
42+ assert . equal ( sessions . length , 1 ) ;
43+ assert . equal ( sessions [ 0 ] . passed , false ) ;
44+ assert . equal ( sessions [ 0 ] . errors . length , 1 ) ;
45+ assert . match ( sessions [ 0 ] . logs [ 0 ] [ 0 ] , / E r r o r : M o d u l e i n t e r c e p t i o n i s n o t a c t i v e ./ ) ;
46+ assert . match ( sessions [ 0 ] . errors [ 0 ] . message , / C o u l d n o t i m p o r t y o u r t e s t m o d u l e ./ ) ;
5147 } ) ;
5248
5349 it ( 'throws when trying to intercept an inexistent module' , async ( ) => {
5450 const { sessions } = await runTests (
5551 {
56- files : [ path . join ( dirname , 'fixtures' , 'inexistent' , 'browser-test.js' ) ] ,
52+ files : [ path . join ( import . meta . dirname , 'fixtures' , 'inexistent' , 'browser-test.js' ) ] ,
5753 browsers : [ chromeLauncher ( ) ] ,
5854 plugins : [ moduleMockingPlugin ( ) , nodeResolvePlugin ( '' , false , { } ) ] ,
5955 } ,
6056 [ ] ,
6157 { allowFailure : true , reportErrors : false } ,
6258 ) ;
6359
64- expect ( sessions . length ) . to . equal ( 1 ) ;
65- expect ( sessions [ 0 ] . passed ) . to . equal ( false ) ;
66- expect ( sessions [ 0 ] . errors . length ) . to . equal ( 1 ) ;
67- expect ( sessions [ 0 ] . logs [ 0 ] [ 0 ] ) . to . match ( / E r r o r : C o u l d n o t r e s o l v e " \/ i n e x i s t e n t - m o d u l e .j s " ./ ) ;
68- expect ( sessions [ 0 ] . errors [ 0 ] . message ) . to . match ( / C o u l d n o t i m p o r t y o u r t e s t m o d u l e ./ ) ;
60+ assert . equal ( sessions . length , 1 ) ;
61+ assert . equal ( sessions [ 0 ] . passed , false ) ;
62+ assert . equal ( sessions [ 0 ] . errors . length , 1 ) ;
63+ assert . match ( sessions [ 0 ] . logs [ 0 ] [ 0 ] , / E r r o r : C o u l d n o t r e s o l v e " \/ i n e x i s t e n t - m o d u l e .j s " ./ ) ;
64+ assert . match ( sessions [ 0 ] . errors [ 0 ] . message , / C o u l d n o t i m p o r t y o u r t e s t m o d u l e ./ ) ;
6965 } ) ;
7066
7167 it ( 'throws when trying to intercept a relative module' , async ( ) => {
7268 const { sessions } = await runTests (
7369 {
74- files : [ path . join ( dirname , 'fixtures' , 'relative' , 'browser-test.js' ) ] ,
70+ files : [ path . join ( import . meta . dirname , 'fixtures' , 'relative' , 'browser-test.js' ) ] ,
7571 browsers : [ chromeLauncher ( ) ] ,
7672 plugins : [ moduleMockingPlugin ( ) , nodeResolvePlugin ( '' , false , { } ) ] ,
7773 } ,
7874 [ ] ,
7975 { allowFailure : true , reportErrors : false } ,
8076 ) ;
8177
82- expect ( sessions . length ) . to . equal ( 1 ) ;
83- expect ( sessions [ 0 ] . passed ) . to . equal ( false ) ;
84- expect ( sessions [ 0 ] . errors . length ) . to . equal ( 1 ) ;
85- expect ( sessions [ 0 ] . logs [ 0 ] [ 0 ] ) . to . match (
78+ assert . equal ( sessions . length , 1 ) ;
79+ assert . equal ( sessions [ 0 ] . passed , false ) ;
80+ assert . equal ( sessions [ 0 ] . errors . length , 1 ) ;
81+ assert . match (
82+ sessions [ 0 ] . logs [ 0 ] [ 0 ] ,
8683 / E r r o r : P a r a m e t e r ` m o d u l e N a m e ` \( ' .\/ f i l e \. j s ' \) c o n t a i n s a r e l a t i v e r e f e r e n c e ./ ,
8784 ) ;
88- expect ( sessions [ 0 ] . errors [ 0 ] . message ) . to . match ( / C o u l d n o t i m p o r t y o u r t e s t m o d u l e ./ ) ;
85+ assert . match ( sessions [ 0 ] . errors [ 0 ] . message , / C o u l d n o t i m p o r t y o u r t e s t m o d u l e ./ ) ;
8986 } ) ;
9087} ) ;
0 commit comments