From bb4ba65df015fc12c6ef98bfb43acb6eb47ee1c6 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Wed, 26 Mar 2025 11:54:35 -0300 Subject: [PATCH 1/2] clean some tests --- scripts/test.js | 33 +++++++++---------- .../jsx_settings_inheritance/input.js | 1 + .../transitive_pinned_dependency1/input.js | 7 ++++ .../transitive_pinned_dependency2/input.js | 6 ++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/scripts/test.js b/scripts/test.js index 010103b42e..3b3320bccb 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -128,39 +128,36 @@ async function runTests() { console.log(`Skipping docstrings tests on ${process.platform}`); } else if (process.platform === "darwin" && os.release().startsWith("22")) { // Workaround for intermittent hangs in CI - console.log("Skipping docstrings tests on macOS 13") + console.log("Skipping docstrings tests on macOS 13"); } else { console.log("Running runtime docstrings tests"); + const docstringsTestsDir = path.join("tests", "docstring_tests"); + const generated_mocha_test_res = path.join( - "tests", - "docstring_tests", + docstringsTestsDir, "generated_mocha_test.res", ); - // Remove `generated_mocha_test.res` if file exists - if (fs.existsSync(generated_mocha_test_res)) { - console.log(`Removing ${generated_mocha_test_res}`); - fs.unlinkSync(generated_mocha_test_res); - } + cp.execSync(`${rescript_exe} clean`, { + cwd: docstringsTestsDir, + stdio: [0, 1, 2], + }); cp.execSync(`${rescript_exe} build`, { - cwd: path.join(__dirname, "..", "tests/docstring_tests"), + cwd: docstringsTestsDir, stdio: [0, 1, 2], }); // Generate rescript file with all tests `generated_mocha_test.res` - cp.execSync( - `node ${path.join("tests", "docstring_tests", "DocTest.res.mjs")}`, - { - cwd: path.join(__dirname, ".."), - stdio: [0, 1, 2], - }, - ); + cp.execSync(`node ${path.join(docstringsTestsDir, "DocTest.res.mjs")}`, { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }); // Build again to check if generated_mocha_test.res has syntax or type erros cp.execSync(`${rescript_exe} build`, { - cwd: path.join(__dirname, "..", "tests/docstring_tests"), + cwd: docstringsTestsDir, stdio: [0, 1, 2], }); @@ -173,7 +170,7 @@ async function runTests() { console.log("Run mocha test"); cp.execSync( - `npx mocha ${path.join("tests", "docstring_tests", "generated_mocha_test.res.mjs")}`, + `npx mocha ${path.join(docstringsTestsDir, "generated_mocha_test.res.mjs")}`, { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], diff --git a/tests/build_tests/jsx_settings_inheritance/input.js b/tests/build_tests/jsx_settings_inheritance/input.js index 96e9ab8353..4ac9fde732 100644 --- a/tests/build_tests/jsx_settings_inheritance/input.js +++ b/tests/build_tests/jsx_settings_inheritance/input.js @@ -2,4 +2,5 @@ var cp = require("child_process"); var { rescript_exe } = require("#cli/bin_path"); +cp.execSync(`${rescript_exe} clean`, { cwd: __dirname }); cp.execSync(rescript_exe, { cwd: __dirname }); diff --git a/tests/build_tests/transitive_pinned_dependency1/input.js b/tests/build_tests/transitive_pinned_dependency1/input.js index 565410ca01..2bb6fc9f5e 100644 --- a/tests/build_tests/transitive_pinned_dependency1/input.js +++ b/tests/build_tests/transitive_pinned_dependency1/input.js @@ -4,6 +4,13 @@ var assert = require("assert"); var fs = require("fs"); var { rescript_exe } = require("#cli/bin_path"); +console.log( + child_process.execSync(`${rescript_exe} clean`, { + encoding: "utf8", + cwd: "./a", + }), +); + console.log( child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }), ); diff --git a/tests/build_tests/transitive_pinned_dependency2/input.js b/tests/build_tests/transitive_pinned_dependency2/input.js index aa9c501afc..8fe0434f16 100644 --- a/tests/build_tests/transitive_pinned_dependency2/input.js +++ b/tests/build_tests/transitive_pinned_dependency2/input.js @@ -4,6 +4,12 @@ var assert = require("assert"); var fs = require("fs"); var { rescript_exe } = require("#cli/bin_path"); +console.log( + child_process.execSync(`${rescript_exe} clean`, { + encoding: "utf8", + cwd: "./a", + }), +); console.log( child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }), ); From 6b07d13e2ffb482f65f9a147920c564b0e4db296 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Sun, 30 Mar 2025 15:43:20 -0300 Subject: [PATCH 2/2] sync with master --- scripts/test.js | 14 ++++++-------- .../build_tests/jsx_settings_inheritance/input.js | 3 ++- .../transitive_pinned_dependency1/input.js | 4 +++- .../transitive_pinned_dependency2/input.js | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/test.js b/scripts/test.js index 1a975f1ef8..c2edd0c4ae 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -143,16 +143,14 @@ if (runtimeDocstrings) { console.log("Running runtime docstrings tests"); const generated_mocha_test_res = path.join( - "tests", - "docstring_tests", + docstringTestDir, "generated_mocha_test.res", ); - // Remove `generated_mocha_test.res` if file exists - if (fs.existsSync(generated_mocha_test_res)) { - console.log(`Removing ${generated_mocha_test_res}`); - fs.unlinkSync(generated_mocha_test_res); - } + await execClean([], { + cwd: docstringTestDir, + stdio: "inherit" + }) await execBuild([], { cwd: docstringTestDir, @@ -180,7 +178,7 @@ if (runtimeDocstrings) { console.log("Run mocha test"); await mocha( - [path.join("tests", "docstring_tests", "generated_mocha_test.res.js")], + [path.join(docstringTestDir, "generated_mocha_test.res.js")], { cwd: projectDir, stdio: "inherit", diff --git a/tests/build_tests/jsx_settings_inheritance/input.js b/tests/build_tests/jsx_settings_inheritance/input.js index 50a4ceabd1..0e3673cdeb 100644 --- a/tests/build_tests/jsx_settings_inheritance/input.js +++ b/tests/build_tests/jsx_settings_inheritance/input.js @@ -2,6 +2,7 @@ import { setup } from "#dev/process"; -const { execBuild } = setup(import.meta.dirname); +const { execBuild, execClean } = setup(import.meta.dirname); +await execClean() await execBuild(); diff --git a/tests/build_tests/transitive_pinned_dependency1/input.js b/tests/build_tests/transitive_pinned_dependency1/input.js index 7ac7da56f3..b366f9d361 100644 --- a/tests/build_tests/transitive_pinned_dependency1/input.js +++ b/tests/build_tests/transitive_pinned_dependency1/input.js @@ -4,7 +4,9 @@ import * as assert from "node:assert"; import { existsSync } from "node:fs"; import { setup } from "#dev/process"; -const { execBuild } = setup("./a"); +const { execBuild, execClean } = setup("./a"); + +await execClean() const output = await execBuild(); console.log(output); diff --git a/tests/build_tests/transitive_pinned_dependency2/input.js b/tests/build_tests/transitive_pinned_dependency2/input.js index 31f05eab92..3eb295d80d 100644 --- a/tests/build_tests/transitive_pinned_dependency2/input.js +++ b/tests/build_tests/transitive_pinned_dependency2/input.js @@ -4,8 +4,8 @@ import * as assert from "node:assert"; import { existsSync } from "node:fs"; import { setup } from "#dev/process"; -const { execBuild } = setup("./a"); - +const { execBuild, execClean } = setup("./a"); +await execClean() const output = await execBuild(); console.log(output);