Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfbd2e64

Browse files
committed
test: modify test case
1 parent8487762 commitfbd2e64

File tree

4 files changed

+66
-45
lines changed

4 files changed

+66
-45
lines changed

‎ava.config.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
exportdefault{
22
files:["test/**/*.ts"],
3-
exclude:["test/temp/**/*.ts"],
43
extensions:["ts"],
54
require:["./run-ts.js"],
65
timeout:"2m",

‎test/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ This directory contains comprehensive unit and integration tests for the RTS (Ru
88

99
```
1010
test/
11-
├── temp/ # Temporary test files (auto-cleaned)
1211
├── index.test.ts # Main functionality tests
1312
├── resolver.test.ts # Module resolver tests
1413
├── transformer.test.ts # Transformer tests
@@ -115,18 +114,18 @@ The RTS system uses a unified architecture where:
115114

116115
##Temporary Files
117116

118-
###`test/temp/` Directory
117+
###System Temporary Directory
119118

120-
All temporary test files are createdin the`test/temp/` directory:
119+
All temporary test files are createdunder thesystem temporary directory (Node`os.tmpdir()`), e.g.`.../rts-tests/...`:
121120
- Automatically cleaned up after tests
122-
-Excluded from git tracking
121+
-Works across Windows and Linux
123122
- Used for file system tests and fixtures
124123
- Supports nested directory structures
125124

126125
###File Management
127126

128127
Tests follow these guidelines for temporary files:
129-
- Create filesin`test/temp/`subdirectories
128+
- Create filesunder`os.tmpdir()` with`rts-tests` prefix andsubdirectories per suite
130129
- Use descriptive file names
131130
- Clean up files in`finally` blocks
132131
- Handle file system errors gracefully

‎test/integration.test.ts‎

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
11
importtestfrom"ava";
22
importfsfrom"fs";
3+
importosfrom"os";
34
importpathfrom"path";
45
import{registerRTS}from"../src/index";
56

6-
// Helper function to create temporary test files
7-
functioncreateTempFile(content:string,filename:string):string{
8-
consttempDir=path.join(__dirname,"temp");
9-
if(!fs.existsSync(tempDir)){
10-
fs.mkdirSync(tempDir,{recursive:true});
11-
}
12-
13-
constfilePath=path.join(tempDir,filename);
14-
fs.writeFileSync(filePath,content);
15-
returnfilePath;
16-
}
17-
187
// Helper function to cleanup temp files
198
functioncleanupTempFiles():void{
20-
consttempDir=path.join(__dirname,"temp");
9+
consttempDir=path.join(os.tmpdir(),"rts-tests","integration");
2110
if(fs.existsSync(tempDir)){
2211
try{
23-
// Try to remove files first
24-
constfiles=fs.readdirSync(tempDir);
25-
for(constfileoffiles){
26-
constfilePath=path.join(tempDir,file);
27-
try{
28-
fs.unlinkSync(filePath);
29-
}catch(error){
30-
// Ignore errors for individual files
31-
}
32-
}
33-
// Then try to remove the directory
34-
fs.rmdirSync(tempDir);
35-
}catch(error){
36-
// Ignore errors for directory removal
37-
}
12+
fs.rmSync(tempDir,{recursive:true,force:true});
13+
}catch{}
3814
}
3915
}
4016

‎test/resolver.test.ts‎

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
importtestfrom"ava";
22
importfsfrom"fs";
3+
importosfrom"os";
34
importpathfrom"path";
45
import{ModuleResolver,typeTransformerHook}from"../src/resolver";
56

@@ -132,7 +133,12 @@ test("register should set up hooks and work with actual module resolution", (t)
132133

133134
try{
134135
// Create a test file
135-
consttestFilePath=path.join(__dirname,"temp","test.custom");
136+
consttestFilePath=path.join(
137+
os.tmpdir(),
138+
"rts-tests",
139+
"resolver",
140+
"test.custom",
141+
);
136142
consttestFileDir=path.dirname(testFilePath);
137143

138144
if(!fs.existsSync(testFileDir)){
@@ -146,7 +152,12 @@ test("register should set up hooks and work with actual module resolution", (t)
146152
t.is(testModule,"test content");
147153
}finally{
148154
resolver.revert();
149-
consttestFilePath=path.join(__dirname,"temp","test.custom");
155+
consttestFilePath=path.join(
156+
os.tmpdir(),
157+
"rts-tests",
158+
"resolver",
159+
"test.custom",
160+
);
150161
if(fs.existsSync(testFilePath)){
151162
fs.unlinkSync(testFilePath);
152163
}
@@ -175,7 +186,12 @@ test("revert should clean up hooks and restore normal behavior", (t) => {
175186

176187
try{
177188
// Create a test file
178-
consttestFilePath=path.join(__dirname,"temp","test-revert.custom");
189+
consttestFilePath=path.join(
190+
os.tmpdir(),
191+
"rts-tests",
192+
"resolver",
193+
"test-revert.custom",
194+
);
179195
consttestFileDir=path.dirname(testFilePath);
180196

181197
if(!fs.existsSync(testFileDir)){
@@ -184,7 +200,7 @@ test("revert should clean up hooks and restore normal behavior", (t) => {
184200

185201
fs.writeFileSync(testFilePath,"test content");
186202
// Test that transformer works
187-
consttestModule1=require("./temp/test-revert.custom");
203+
consttestModule1=require(testFilePath);
188204
t.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
196212
t.notThrows(()=>resolver.revert());
197213
}finally{
198-
consttestFilePath=path.join(__dirname,"temp","test-revert.custom");
214+
consttestFilePath=path.join(
215+
os.tmpdir(),
216+
"rts-tests",
217+
"resolver",
218+
"test-revert.custom",
219+
);
199220
if(fs.existsSync(testFilePath)){
200221
fs.unlinkSync(testFilePath);
201222
}
@@ -244,7 +265,12 @@ test("ModuleResolver should work with multiple transformers", (t) => {
244265

245266
try{
246267
// Create test files
247-
consttestDir=path.join(__dirname,"temp","multi-transform");
268+
consttestDir=path.join(
269+
os.tmpdir(),
270+
"rts-tests",
271+
"resolver",
272+
"multi-transform",
273+
);
248274
if(!fs.existsSync(testDir)){
249275
fs.mkdirSync(testDir,{recursive:true});
250276
}
@@ -264,7 +290,12 @@ test("ModuleResolver should work with multiple transformers", (t) => {
264290
t.truthy(jsModule);
265291
}finally{
266292
resolver.revert();
267-
consttestDir=path.join(__dirname,"temp","multi-transform");
293+
consttestDir=path.join(
294+
os.tmpdir(),
295+
"rts-tests",
296+
"resolver",
297+
"multi-transform",
298+
);
268299
if(fs.existsSync(testDir)){
269300
fs.rmSync(testDir,{recursive:true,force:true});
270301
}
@@ -297,7 +328,13 @@ test("ModuleResolver should handle alias resolution with transformers", (t) => {
297328

298329
try{
299330
// Create test directory structure
300-
constcomponentsDir=path.join(__dirname,"temp","src","components");
331+
constcomponentsDir=path.join(
332+
os.tmpdir(),
333+
"rts-tests",
334+
"resolver",
335+
"src",
336+
"components",
337+
);
301338
if(!fs.existsSync(componentsDir)){
302339
fs.mkdirSync(componentsDir,{recursive:true});
303340
}
@@ -311,7 +348,7 @@ test("ModuleResolver should handle alias resolution with transformers", (t) => {
311348
t.pass();
312349
}finally{
313350
resolver.revert();
314-
consttempDir=path.join(__dirname,"temp","src");
351+
consttempDir=path.join(os.tmpdir(),"rts-tests","resolver","src");
315352
if(fs.existsSync(tempDir)){
316353
fs.rmSync(tempDir,{recursive:true,force:true});
317354
}
@@ -367,7 +404,12 @@ test("ModuleResolver should handle transformer priority correctly", (t) => {
367404

368405
try{
369406
// Create test files with different extensions
370-
consttestDir=path.join(__dirname,"temp","priority-test");
407+
consttestDir=path.join(
408+
os.tmpdir(),
409+
"rts-tests",
410+
"resolver",
411+
"priority-test",
412+
);
371413
if(!fs.existsSync(testDir)){
372414
fs.mkdirSync(testDir,{recursive:true});
373415
}
@@ -386,7 +428,12 @@ test("ModuleResolver should handle transformer priority correctly", (t) => {
386428
t.truthy(customModule);
387429
}finally{
388430
resolver.revert();
389-
consttestDir=path.join(__dirname,"temp","priority-test");
431+
consttestDir=path.join(
432+
os.tmpdir(),
433+
"rts-tests",
434+
"resolver",
435+
"priority-test",
436+
);
390437
if(fs.existsSync(testDir)){
391438
fs.rmSync(testDir,{recursive:true,force:true});
392439
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp