11import test from "ava" ;
22import fs from "fs" ;
3+ import os from "os" ;
34import path from "path" ;
45import { ModuleResolver , type TransformerHook } from "../src/resolver" ;
56
@@ -132,7 +133,12 @@ test("register should set up hooks and work with actual module resolution", (t)
132133
133134try {
134135// Create a test file
135- const testFilePath = path . join ( __dirname , "temp" , "test.custom" ) ;
136+ const testFilePath = path . join (
137+ os . tmpdir ( ) ,
138+ "rts-tests" ,
139+ "resolver" ,
140+ "test.custom" ,
141+ ) ;
136142const testFileDir = path . dirname ( testFilePath ) ;
137143
138144if ( ! fs . existsSync ( testFileDir ) ) {
@@ -146,7 +152,12 @@ test("register should set up hooks and work with actual module resolution", (t)
146152t . is ( testModule , "test content" ) ;
147153} finally {
148154resolver . revert ( ) ;
149- const testFilePath = path . join ( __dirname , "temp" , "test.custom" ) ;
155+ const testFilePath = path . join (
156+ os . tmpdir ( ) ,
157+ "rts-tests" ,
158+ "resolver" ,
159+ "test.custom" ,
160+ ) ;
150161if ( fs . existsSync ( testFilePath ) ) {
151162fs . unlinkSync ( testFilePath ) ;
152163}
@@ -175,7 +186,12 @@ test("revert should clean up hooks and restore normal behavior", (t) => {
175186
176187try {
177188// Create a test file
178- const testFilePath = path . join ( __dirname , "temp" , "test-revert.custom" ) ;
189+ const testFilePath = path . join (
190+ os . tmpdir ( ) ,
191+ "rts-tests" ,
192+ "resolver" ,
193+ "test-revert.custom" ,
194+ ) ;
179195const testFileDir = path . dirname ( testFilePath ) ;
180196
181197if ( ! fs . existsSync ( testFileDir ) ) {
@@ -184,7 +200,7 @@ test("revert should clean up hooks and restore normal behavior", (t) => {
184200
185201fs . writeFileSync ( testFilePath , "test content" ) ;
186202// Test that transformer works
187- const testModule1 = require ( "./temp/test-revert.custom" ) ;
203+ const testModule1 = require ( testFilePath ) ;
188204t . is ( testModule1 , "test content" ) ;
189205
190206// Revert hooks
@@ -195,7 +211,12 @@ test("revert should clean up hooks and restore normal behavior", (t) => {
195211// We'll just test that revert doesn't throw
196212t . notThrows ( ( ) => resolver . revert ( ) ) ;
197213} finally {
198- const testFilePath = path . join ( __dirname , "temp" , "test-revert.custom" ) ;
214+ const testFilePath = path . join (
215+ os . tmpdir ( ) ,
216+ "rts-tests" ,
217+ "resolver" ,
218+ "test-revert.custom" ,
219+ ) ;
199220if ( fs . existsSync ( testFilePath ) ) {
200221fs . unlinkSync ( testFilePath ) ;
201222}
@@ -244,7 +265,12 @@ test("ModuleResolver should work with multiple transformers", (t) => {
244265
245266try {
246267// Create test files
247- const testDir = path . join ( __dirname , "temp" , "multi-transform" ) ;
268+ const testDir = path . join (
269+ os . tmpdir ( ) ,
270+ "rts-tests" ,
271+ "resolver" ,
272+ "multi-transform" ,
273+ ) ;
248274if ( ! fs . existsSync ( testDir ) ) {
249275fs . mkdirSync ( testDir , { recursive :true } ) ;
250276}
@@ -264,7 +290,12 @@ test("ModuleResolver should work with multiple transformers", (t) => {
264290t . truthy ( jsModule ) ;
265291} finally {
266292resolver . revert ( ) ;
267- const testDir = path . join ( __dirname , "temp" , "multi-transform" ) ;
293+ const testDir = path . join (
294+ os . tmpdir ( ) ,
295+ "rts-tests" ,
296+ "resolver" ,
297+ "multi-transform" ,
298+ ) ;
268299if ( fs . existsSync ( testDir ) ) {
269300fs . rmSync ( testDir , { recursive :true , force :true } ) ;
270301}
@@ -297,7 +328,13 @@ test("ModuleResolver should handle alias resolution with transformers", (t) => {
297328
298329try {
299330// Create test directory structure
300- const componentsDir = path . join ( __dirname , "temp" , "src" , "components" ) ;
331+ const componentsDir = path . join (
332+ os . tmpdir ( ) ,
333+ "rts-tests" ,
334+ "resolver" ,
335+ "src" ,
336+ "components" ,
337+ ) ;
301338if ( ! fs . existsSync ( componentsDir ) ) {
302339fs . mkdirSync ( componentsDir , { recursive :true } ) ;
303340}
@@ -311,7 +348,7 @@ test("ModuleResolver should handle alias resolution with transformers", (t) => {
311348t . pass ( ) ;
312349} finally {
313350resolver . revert ( ) ;
314- const tempDir = path . join ( __dirname , "temp " , "src" ) ;
351+ const tempDir = path . join ( os . tmpdir ( ) , "rts-tests" , "resolver ", "src" ) ;
315352if ( fs . existsSync ( tempDir ) ) {
316353fs . rmSync ( tempDir , { recursive :true , force :true } ) ;
317354}
@@ -367,7 +404,12 @@ test("ModuleResolver should handle transformer priority correctly", (t) => {
367404
368405try {
369406// Create test files with different extensions
370- const testDir = path . join ( __dirname , "temp" , "priority-test" ) ;
407+ const testDir = path . join (
408+ os . tmpdir ( ) ,
409+ "rts-tests" ,
410+ "resolver" ,
411+ "priority-test" ,
412+ ) ;
371413if ( ! fs . existsSync ( testDir ) ) {
372414fs . mkdirSync ( testDir , { recursive :true } ) ;
373415}
@@ -386,7 +428,12 @@ test("ModuleResolver should handle transformer priority correctly", (t) => {
386428t . truthy ( customModule ) ;
387429} finally {
388430resolver . revert ( ) ;
389- const testDir = path . join ( __dirname , "temp" , "priority-test" ) ;
431+ const testDir = path . join (
432+ os . tmpdir ( ) ,
433+ "rts-tests" ,
434+ "resolver" ,
435+ "priority-test" ,
436+ ) ;
390437if ( fs . existsSync ( testDir ) ) {
391438fs . rmSync ( testDir , { recursive :true , force :true } ) ;
392439}