Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/ten-chefs-slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"rts.js": patch
---

Ci (release): Triggering release when PR is merged into master; Test temporary files to use system temporary directory instead
-Ci: Modify. ithub/workflows/release. yml
-The triggering condition is changed to pull_dequest.clost to master, and only executed when merged==true
-Retain manual triggering of workflow_ispatch
-Change the workflow name to release
-Upgrade pnpm/action setup to v10 and adjust the installation order to match pnpm cache
-Test: Migration of temporary files to system temporary directory
-All use cases use the rts tests/* subdirectories under os. tpdir() uniformly, compatible with Windows/Linux
-Adjust file creation and cleanup to fs.rmSync (..., {recursive: true, force: true})
-Delete the test/temp directory and related dependency paths in the repository
-Chore (ava): Remove the exclusion of test/temp/* */*. ts in ava.cnfig.js
-Docs (test): Update temporary file policy instructions in test/README.md
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test-module.js
temp-config.json

# Changeset files (keep README.md but ignore individual changeset files)
.changeset/*.md
!.changeset/README.md

# IDE and editor files
Expand Down
1 change: 0 additions & 1 deletion ava.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default {
files: ["test/**/*.ts"],
exclude: ["test/temp/**/*.ts"],
extensions: ["ts"],
require: ["./run-ts.js"],
timeout: "2m",
Expand Down
9 changes: 4 additions & 5 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ This directory contains comprehensive unit and integration tests for the RTS (Ru

```
test/
├── temp/ # Temporary test files (auto-cleaned)
├── index.test.ts # Main functionality tests
├── resolver.test.ts # Module resolver tests
├── transformer.test.ts # Transformer tests
Expand Down Expand Up @@ -115,18 +114,18 @@ The RTS system uses a unified architecture where:

## Temporary Files

### `test/temp/` Directory
### System Temporary Directory

All temporary test files are created in the `test/temp/` directory:
All temporary test files are created under the system temporary directory (Node `os.tmpdir()`), e.g. `.../rts-tests/...`:
- Automatically cleaned up after tests
- Excluded from git tracking
- Works across Windows and Linux
- Used for file system tests and fixtures
- Supports nested directory structures

### File Management

Tests follow these guidelines for temporary files:
- Create files in `test/temp/` subdirectories
- Create files under `os.tmpdir()` with `rts-tests` prefix and subdirectories per suite
- Use descriptive file names
- Clean up files in `finally` blocks
- Handle file system errors gracefully
Expand Down
32 changes: 4 additions & 28 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
import test from "ava";
import fs from "fs";
import os from "os";
import path from "path";
import { registerRTS } from "../src/index";

// Helper function to create temporary test files
function createTempFile(content: string, filename: string): string {
const tempDir = path.join(__dirname, "temp");
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true });
}

const filePath = path.join(tempDir, filename);
fs.writeFileSync(filePath, content);
return filePath;
}

// Helper function to cleanup temp files
function cleanupTempFiles(): void {
const tempDir = path.join(__dirname, "temp");
const tempDir = path.join(os.tmpdir(), "rts-tests", "integration");
if (fs.existsSync(tempDir)) {
try {
// Try to remove files first
const files = fs.readdirSync(tempDir);
for (const file of files) {
const filePath = path.join(tempDir, file);
try {
fs.unlinkSync(filePath);
} catch (error) {
// Ignore errors for individual files
}
}
// Then try to remove the directory
fs.rmdirSync(tempDir);
} catch (error) {
// Ignore errors for directory removal
}
fs.rmSync(tempDir, { recursive: true, force: true });
} catch {}
}
}

Expand Down
69 changes: 58 additions & 11 deletions test/resolver.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import test from "ava";
import fs from "fs";
import os from "os";
import path from "path";
import { ModuleResolver, type TransformerHook } from "../src/resolver";

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

try {
// Create a test file
const testFilePath = path.join(__dirname, "temp", "test.custom");
const testFilePath = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"test.custom",
);
const testFileDir = path.dirname(testFilePath);

if (!fs.existsSync(testFileDir)) {
Expand All @@ -146,7 +152,12 @@ test("register should set up hooks and work with actual module resolution", (t)
t.is(testModule, "test content");
} finally {
resolver.revert();
const testFilePath = path.join(__dirname, "temp", "test.custom");
const testFilePath = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"test.custom",
);
if (fs.existsSync(testFilePath)) {
fs.unlinkSync(testFilePath);
}
Expand Down Expand Up @@ -175,7 +186,12 @@ test("revert should clean up hooks and restore normal behavior", (t) => {

try {
// Create a test file
const testFilePath = path.join(__dirname, "temp", "test-revert.custom");
const testFilePath = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"test-revert.custom",
);
const testFileDir = path.dirname(testFilePath);

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

fs.writeFileSync(testFilePath, "test content");
// Test that transformer works
const testModule1 = require("./temp/test-revert.custom");
const testModule1 = require(testFilePath);
t.is(testModule1, "test content");

// Revert hooks
Expand All @@ -195,7 +211,12 @@ test("revert should clean up hooks and restore normal behavior", (t) => {
// We'll just test that revert doesn't throw
t.notThrows(() => resolver.revert());
} finally {
const testFilePath = path.join(__dirname, "temp", "test-revert.custom");
const testFilePath = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"test-revert.custom",
);
if (fs.existsSync(testFilePath)) {
fs.unlinkSync(testFilePath);
}
Expand Down Expand Up @@ -244,7 +265,12 @@ test("ModuleResolver should work with multiple transformers", (t) => {

try {
// Create test files
const testDir = path.join(__dirname, "temp", "multi-transform");
const testDir = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"multi-transform",
);
if (!fs.existsSync(testDir)) {
fs.mkdirSync(testDir, { recursive: true });
}
Expand All @@ -264,7 +290,12 @@ test("ModuleResolver should work with multiple transformers", (t) => {
t.truthy(jsModule);
} finally {
resolver.revert();
const testDir = path.join(__dirname, "temp", "multi-transform");
const testDir = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"multi-transform",
);
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true });
}
Expand Down Expand Up @@ -297,7 +328,13 @@ test("ModuleResolver should handle alias resolution with transformers", (t) => {

try {
// Create test directory structure
const componentsDir = path.join(__dirname, "temp", "src", "components");
const componentsDir = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"src",
"components",
);
if (!fs.existsSync(componentsDir)) {
fs.mkdirSync(componentsDir, { recursive: true });
}
Expand All @@ -311,7 +348,7 @@ test("ModuleResolver should handle alias resolution with transformers", (t) => {
t.pass();
} finally {
resolver.revert();
const tempDir = path.join(__dirname, "temp", "src");
const tempDir = path.join(os.tmpdir(), "rts-tests", "resolver", "src");
if (fs.existsSync(tempDir)) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
Expand Down Expand Up @@ -367,7 +404,12 @@ test("ModuleResolver should handle transformer priority correctly", (t) => {

try {
// Create test files with different extensions
const testDir = path.join(__dirname, "temp", "priority-test");
const testDir = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"priority-test",
);
if (!fs.existsSync(testDir)) {
fs.mkdirSync(testDir, { recursive: true });
}
Expand All @@ -386,7 +428,12 @@ test("ModuleResolver should handle transformer priority correctly", (t) => {
t.truthy(customModule);
} finally {
resolver.revert();
const testDir = path.join(__dirname, "temp", "priority-test");
const testDir = path.join(
os.tmpdir(),
"rts-tests",
"resolver",
"priority-test",
);
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true });
}
Expand Down