Skip to content

Commit

Permalink
chore: improve paths configuration and update "how to use" section (#568
Browse files Browse the repository at this point in the history
)

* chore: improve paths configuration and update "how to use" section

* fix typo in usage example

* Remove the resolveTestCaseDir function. Resolve testDir, ignoredTestDir and boolean just in place again

* start with import.meta.dirname

* default the path to ./ (same as import.meta.dirname in this case) and update comment

* remove "relative to scripts directory"

* resolve the whole path at the the top of the file for better clarity
  • Loading branch information
shonya3 committed Mar 15, 2024
1 parent 8ea80ff commit 33abf4f
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions scripts/gen-esbuild-test.js
Expand Up @@ -8,12 +8,24 @@ import * as changeCase from 'change-case'
import chalk from 'chalk'
import * as dedent from 'dedent'

const __dirname = import.meta.dirname

// How to use this script
// 1. Adding a test golang file under this dir or wherever you want, and modify the source path
// 2. `let testDir = path.resolve(__dirname, "test", testCaseName);` Modify this testDir, by default,
// The script will generate testCases under `${__dirname}/test`

// 1. Set the test suite name.

/** @type {TestSuiteName} {@link suites} */
const SUITE_NAME = 'default'

// 2. Set the tests root directory

const TESTS_ROOT_DIR = path.resolve(
import.meta.dirname,
'tests/esbuild',
SUITE_NAME,
)

// 3. Download .go test source file located in the suites object
// for each suite and place it under "scripts" dir.
// (You can skip this step, the script can download it for you)

/**
* Constant object containing test suites.
Expand Down Expand Up @@ -91,11 +103,8 @@ async function readTestSuiteSource(testSuiteName) {
}
}

/** @type {TestSuiteName} */
const TEST_SUITE_NAME = 'default'
const currentSuite = suites[TEST_SUITE_NAME]
/** The contents of the .go test source file. {@link suites} */
const source = await readTestSuiteSource(TEST_SUITE_NAME)
const source = await readTestSuiteSource(SUITE_NAME)
const ignoredTestName = [
'ts',
'txt',
Expand Down Expand Up @@ -178,16 +187,8 @@ for (let i = 0, len = tree.rootNode.namedChildren.length; i < len; i++) {
if (ignoredTestName.some((name) => testCaseName.includes(name))) {
continue
}
let testDir = path.resolve(
__dirname,
`../crates/rolldown/tests/esbuild/${currentSuite.name}`,
testCaseName,
)
let ignoredTestDir = path.resolve(
__dirname,
`../crates/rolldown/tests/esbuild/${currentSuite.name}`,
`.${testCaseName}`,
)
const testDir = path.resolve(TESTS_ROOT_DIR, testCaseName)
const ignoredTestDir = path.resolve(TESTS_ROOT_DIR, `.${testCaseName}`)

// Cause if you withdraw directory in git system, git will cleanup dir but leave the directory alone
if (
Expand Down

0 comments on commit 33abf4f

Please sign in to comment.