diff --git a/.changeset/ten-chefs-slide.md b/.changeset/ten-chefs-slide.md new file mode 100644 index 0000000..4b42889 --- /dev/null +++ b/.changeset/ten-chefs-slide.md @@ -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 diff --git a/.gitignore b/.gitignore index 89ff8b5..4baa3c0 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/ava.config.js b/ava.config.js index 862229b..467f9db 100644 --- a/ava.config.js +++ b/ava.config.js @@ -1,6 +1,5 @@ export default { files: ["test/**/*.ts"], - exclude: ["test/temp/**/*.ts"], extensions: ["ts"], require: ["./run-ts.js"], timeout: "2m", diff --git a/test/README.md b/test/README.md index c64949a..c86b7d1 100644 --- a/test/README.md +++ b/test/README.md @@ -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 @@ -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 diff --git a/test/integration.test.ts b/test/integration.test.ts index 995ad82..db1e3a5 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -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 {} } } diff --git a/test/resolver.test.ts b/test/resolver.test.ts index 003234c..70f724d 100644 --- a/test/resolver.test.ts +++ b/test/resolver.test.ts @@ -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"; @@ -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)) { @@ -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); } @@ -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)) { @@ -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 @@ -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); } @@ -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 }); } @@ -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 }); } @@ -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 }); } @@ -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 }); } @@ -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 }); } @@ -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 }); }