From 89842e2c7f9284cb92d090e7147a7d6b4b2b1b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 01:25:09 -0300 Subject: [PATCH 01/24] feat: watch dynamic imports --- src/bin/index.ts | 41 +++++++++++++++++++----- src/polyfills/fs.ts | 12 +++++++ src/services/map-tests.ts | 53 +++++++++++++++++++++++++++++++ test/unit/map-tests.test.ts | 62 +++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 8 deletions(-) create mode 100644 src/services/map-tests.ts create mode 100644 test/unit/map-tests.test.ts diff --git a/src/bin/index.ts b/src/bin/index.ts index 16a33e5b..81cebd96 100644 --- a/src/bin/index.ts +++ b/src/bin/index.ts @@ -14,6 +14,7 @@ import { platformIsValid } from '../helpers/get-runtime.js'; import { format } from '../helpers/format.js'; import { write } from '../helpers/logs.js'; import { hr } from '../helpers/hr.js'; +import { mapTests } from '../services/map-tests.js'; import { watch } from '../services/watch.js'; import { poku } from '../modules/poku.js'; import { kill } from '../modules/processes.js'; @@ -111,12 +112,34 @@ import type { Configs } from '../@types/poku.js'; if (watchMode) { const executing = new Set(); const interval = Number(getArg('watch-interval')) || 1500; - - fileResults.success.clear(); - fileResults.fail.clear(); - - hr(); - write(`Watching: ${dirs.join(', ')}`); + const resultsClear = () => { + fileResults.success.clear(); + fileResults.fail.clear(); + }; + + resultsClear(); + + mapTests('.', dirs).then((mappedTests) => [ + Array.from(mappedTests.keys()).forEach((mappedTest) => { + watch(mappedTest, (file, event) => { + if (event === 'change') { + if (executing.has(file)) return; + + executing.add(file); + resultsClear(); + + const tests = mappedTests.get(file); + if (!tests) return; + + poku(tests, options).then(() => { + setTimeout(() => { + executing.delete(file); + }, interval); + }); + } + }); + }), + ]); dirs.forEach((dir) => { watch(dir, (file, event) => { @@ -124,8 +147,7 @@ import type { Configs } from '../@types/poku.js'; if (executing.has(file)) return; executing.add(file); - fileResults.success.clear(); - fileResults.fail.clear(); + resultsClear(); poku(file, options).then(() => { setTimeout(() => { @@ -135,6 +157,9 @@ import type { Configs } from '../@types/poku.js'; } }); }); + + hr(); + write(`Watching: ${dirs.join(', ')}`); } })(); diff --git a/src/polyfills/fs.ts b/src/polyfills/fs.ts index 74e07374..df4e107a 100644 --- a/src/polyfills/fs.ts +++ b/src/polyfills/fs.ts @@ -3,6 +3,7 @@ import { stat as nodeStat, readdir as nodeReaddir, + readFile as nodeReadFile, type Dirent, type Stats, } from 'node:fs'; @@ -27,4 +28,15 @@ export const stat = (path: string): Promise => { }); }; +export const readFile = ( + path: string, + encoding: BufferEncoding = 'utf-8' +): Promise => + new Promise((resolve, reject) => { + nodeReadFile(path, encoding, (err, data) => { + if (err) reject(err); + else resolve(data); + }); + }); + /* c8 ignore stop */ diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts new file mode 100644 index 00000000..46a1c080 --- /dev/null +++ b/src/services/map-tests.ts @@ -0,0 +1,53 @@ +/* c8 ignore next */ +import { relative, dirname } from 'node:path'; +import { stat, readFile } from '../polyfills/fs.js'; +import { listFiles } from '../modules/list-files.js'; + +const filter = /\.(js|cjs|mjs|ts|cts|mts)$/; + +const normalizePath = (filePath: string) => + filePath.replace(/(\.\.\/|\.\/)/g, ''); + +/* c8 ignore next */ +export const mapTests = async (srcDir: string, testPaths: string[]) => { + const allTestFiles: string[] = []; + const allSrcFiles = await listFiles(srcDir, { filter }); + const importMap = new Map(); + + for (const testPath of testPaths) { + const stats = await stat(testPath); + + if (stats.isDirectory()) { + const testFiles = await listFiles(testPath, { filter }); + + allTestFiles.push(...testFiles); + } else if (stats.isFile() && filter.test(testPath)) + allTestFiles.push(testPath); + } + + for (const testFile of allTestFiles) { + const content = await readFile(testFile, 'utf-8'); + + for (const srcFile of allSrcFiles) { + const relativePath = normalizePath( + relative(dirname(testFile), srcFile).replace(/\\/g, '/') + ); + + const normalizedSrcFile = normalizePath(srcFile.replace(/\\/g, '/')); + + /* c8 ignore start */ + if ( + content.includes(relativePath.replace(filter, '')) || + content.includes(normalizedSrcFile) + ) { + if (!importMap.has(normalizedSrcFile)) + importMap.set(normalizedSrcFile, []); + + importMap.get(normalizedSrcFile)!.push(testFile); + } + /* c8 ignore stop */ + } + } + + return importMap; +}; diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts new file mode 100644 index 00000000..6fcbf53a --- /dev/null +++ b/test/unit/map-tests.test.ts @@ -0,0 +1,62 @@ +import process from 'node:process'; +import { it } from '../../src/modules/it.js'; +import { describe } from '../../src/modules/describe.js'; +import { beforeEach, afterEach } from '../../src/modules/each.js'; +import { assert } from '../../src/modules/assert.js'; +import { nodeVersion } from '../../src/helpers/get-runtime.js'; +import { mapTests } from '../../src/services/map-tests.js'; +import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; +import { join } from 'node:path'; + +if (nodeVersion && nodeVersion < 14) process.exit(0); + +const createFileSync = (filePath: string, content: string) => { + writeFileSync(filePath, content); +}; + +const createDirSync = (dirPath: string) => { + mkdirSync(dirPath, { recursive: true }); +}; + +const removeDirSync = (dirPath: string) => { + rmSync(dirPath, { recursive: true, force: true }); +}; + +const testSrcDir = 'test-src'; +const testTestDir = 'test-tests'; + +describe('mapTests', async () => { + beforeEach(() => { + createDirSync(testSrcDir); + createDirSync(testTestDir); + createFileSync(join(testSrcDir, 'example.js'), 'export const foo = 42;'); + createFileSync( + join(testTestDir, 'example.test.js'), + 'import { foo } from "../test-src/example.js";' + ); + }); + + afterEach(() => { + removeDirSync(testSrcDir); + removeDirSync(testTestDir); + }); + + await it('should map test files to their corresponding source files', async () => { + const importMap = await mapTests(testSrcDir, [testTestDir]); + const expected = new Map([ + ['test-src/example.js', ['test-tests/example.test.js']], + ]); + + assert.deepStrictEqual(importMap, expected); + }); + + await it('should map single test file correctly', async () => { + const singleTestFile = join(testTestDir, 'example.test.js'); + const importMap = await mapTests(testSrcDir, [singleTestFile]); + const expected = new Map([ + ['test-src/example.js', ['test-tests/example.test.js']], + ]); + + assert.deepStrictEqual(importMap, expected); + }); +}); From e1ff072f75e79ee61bd31833fa8241bcb6e0c9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 01:27:09 -0300 Subject: [PATCH 02/24] chore: organize imports --- test/unit/map-tests.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 6fcbf53a..64814c6c 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -1,12 +1,12 @@ import process from 'node:process'; +import { join } from 'node:path'; +import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; import { it } from '../../src/modules/it.js'; import { describe } from '../../src/modules/describe.js'; import { beforeEach, afterEach } from '../../src/modules/each.js'; import { assert } from '../../src/modules/assert.js'; import { nodeVersion } from '../../src/helpers/get-runtime.js'; import { mapTests } from '../../src/services/map-tests.js'; -import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; -import { join } from 'node:path'; if (nodeVersion && nodeVersion < 14) process.exit(0); From 0c28d0487ce0d15cf5c612ec2212b1ab00ae127b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 01:28:42 -0300 Subject: [PATCH 03/24] ci: ignore tests for Node <14 --- test/unit/map-tests.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 64814c6c..1fbd4782 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -1,15 +1,16 @@ import process from 'node:process'; +import { nodeVersion } from '../../src/helpers/get-runtime.js'; + +if (nodeVersion && nodeVersion < 14) process.exit(0); + import { join } from 'node:path'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; import { it } from '../../src/modules/it.js'; import { describe } from '../../src/modules/describe.js'; import { beforeEach, afterEach } from '../../src/modules/each.js'; import { assert } from '../../src/modules/assert.js'; -import { nodeVersion } from '../../src/helpers/get-runtime.js'; import { mapTests } from '../../src/services/map-tests.js'; -if (nodeVersion && nodeVersion < 14) process.exit(0); - const createFileSync = (filePath: string, content: string) => { writeFileSync(filePath, content); }; From e09b50516435c71f8ac228dc444ca1bf2277ef75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 01:54:50 -0300 Subject: [PATCH 04/24] debug: dynamic sep --- package.json | 1 + src/services/map-tests.ts | 7 +++++-- website/docs/documentation/poku/options/watch.mdx | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fb0f47ab..ddb9ed78 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "run", "queue", "queuing", + "watch", "nodejs", "node", "cli-app", diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index 46a1c080..e337d589 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -1,12 +1,15 @@ /* c8 ignore next */ -import { relative, dirname } from 'node:path'; +import { relative, dirname, sep } from 'node:path'; import { stat, readFile } from '../polyfills/fs.js'; import { listFiles } from '../modules/list-files.js'; const filter = /\.(js|cjs|mjs|ts|cts|mts)$/; const normalizePath = (filePath: string) => - filePath.replace(/(\.\.\/|\.\/)/g, ''); + filePath + .replace(/(\.\/)/g, '') + .replace(/^\.+/, '') + .replace(/[/\\]+/g, sep); /* c8 ignore next */ export const mapTests = async (srcDir: string, testPaths: string[]) => { diff --git a/website/docs/documentation/poku/options/watch.mdx b/website/docs/documentation/poku/options/watch.mdx index f73a7c57..e81c9de0 100644 --- a/website/docs/documentation/poku/options/watch.mdx +++ b/website/docs/documentation/poku/options/watch.mdx @@ -4,9 +4,9 @@ sidebar_position: 9 # `watch` -Watches the events on test paths (after running all the tests), re-running the tests files that are updated for each new event. +Watches the events on tests and files that contains tests (after running all the tests), re-running the tests files that are updated for each new event. -> Currently, `watch` mode only watches for events from test files and directories. +> Note that the import mapping only looks for direct imports. ## CLI From f6d49d9f5438bd5d81aa00f4598bd5cc45e87abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:02:16 -0300 Subject: [PATCH 05/24] debug: dynamic sep --- test/unit/map-tests.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 1fbd4782..57043193 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -3,7 +3,7 @@ import { nodeVersion } from '../../src/helpers/get-runtime.js'; if (nodeVersion && nodeVersion < 14) process.exit(0); -import { join } from 'node:path'; +import { join, sep } from 'node:path'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; import { it } from '../../src/modules/it.js'; import { describe } from '../../src/modules/describe.js'; @@ -23,6 +23,8 @@ const removeDirSync = (dirPath: string) => { rmSync(dirPath, { recursive: true, force: true }); }; +const dsep = (file: string) => file.replace(/[/\\]+/g, sep); + const testSrcDir = 'test-src'; const testTestDir = 'test-tests'; @@ -45,9 +47,12 @@ describe('mapTests', async () => { await it('should map test files to their corresponding source files', async () => { const importMap = await mapTests(testSrcDir, [testTestDir]); const expected = new Map([ - ['test-src/example.js', ['test-tests/example.test.js']], + [dsep('test-src/example.js'), [dsep('test-tests/example.test.js')]], ]); + console.log(importMap); + console.log(expected); + assert.deepStrictEqual(importMap, expected); }); @@ -55,7 +60,7 @@ describe('mapTests', async () => { const singleTestFile = join(testTestDir, 'example.test.js'); const importMap = await mapTests(testSrcDir, [singleTestFile]); const expected = new Map([ - ['test-src/example.js', ['test-tests/example.test.js']], + [dsep('test-src/example.js'), [dsep('test-tests/example.test.js')]], ]); assert.deepStrictEqual(importMap, expected); From 89075ff40c34b104412706c9ad4b21eb2c9f7fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:09:38 -0300 Subject: [PATCH 06/24] debug: dynamic sep --- test/unit/map-tests.test.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 57043193..93f4b853 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -28,22 +28,22 @@ const dsep = (file: string) => file.replace(/[/\\]+/g, sep); const testSrcDir = 'test-src'; const testTestDir = 'test-tests'; -describe('mapTests', async () => { - beforeEach(() => { - createDirSync(testSrcDir); - createDirSync(testTestDir); - createFileSync(join(testSrcDir, 'example.js'), 'export const foo = 42;'); - createFileSync( - join(testTestDir, 'example.test.js'), - 'import { foo } from "../test-src/example.js";' - ); - }); +beforeEach(() => { + createDirSync(testSrcDir); + createDirSync(testTestDir); + createFileSync(join(testSrcDir, 'example.js'), 'export const foo = 42;'); + createFileSync( + join(testTestDir, 'example.test.js'), + 'import { foo } from "../test-src/example.js";' + ); +}); - afterEach(() => { - removeDirSync(testSrcDir); - removeDirSync(testTestDir); - }); +afterEach(() => { + removeDirSync(testSrcDir); + removeDirSync(testTestDir); +}); +describe('mapTests', async () => { await it('should map test files to their corresponding source files', async () => { const importMap = await mapTests(testSrcDir, [testTestDir]); const expected = new Map([ From ef6e456643f95935f289854f12f68b14c91478db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:15:36 -0300 Subject: [PATCH 07/24] debug: posix --- test/unit/map-tests.test.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 93f4b853..2bab0e4d 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -3,7 +3,7 @@ import { nodeVersion } from '../../src/helpers/get-runtime.js'; if (nodeVersion && nodeVersion < 14) process.exit(0); -import { join, sep } from 'node:path'; +import { join, posix } from 'node:path'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; import { it } from '../../src/modules/it.js'; import { describe } from '../../src/modules/describe.js'; @@ -23,8 +23,6 @@ const removeDirSync = (dirPath: string) => { rmSync(dirPath, { recursive: true, force: true }); }; -const dsep = (file: string) => file.replace(/[/\\]+/g, sep); - const testSrcDir = 'test-src'; const testTestDir = 'test-tests'; @@ -36,6 +34,10 @@ beforeEach(() => { join(testTestDir, 'example.test.js'), 'import { foo } from "../test-src/example.js";' ); + createFileSync( + join(testTestDir, 'exampleAbsolute.test.js'), + `import { foo } from "${posix.join(testSrcDir, 'example.js')}";` + ); }); afterEach(() => { @@ -47,7 +49,13 @@ describe('mapTests', async () => { await it('should map test files to their corresponding source files', async () => { const importMap = await mapTests(testSrcDir, [testTestDir]); const expected = new Map([ - [dsep('test-src/example.js'), [dsep('test-tests/example.test.js')]], + [ + posix.join(testSrcDir, 'example.js'), + [ + posix.join(testTestDir, 'example.test.js'), + posix.join(testTestDir, 'exampleAbsolute.test.js'), + ], + ], ]); console.log(importMap); @@ -60,7 +68,10 @@ describe('mapTests', async () => { const singleTestFile = join(testTestDir, 'example.test.js'); const importMap = await mapTests(testSrcDir, [singleTestFile]); const expected = new Map([ - [dsep('test-src/example.js'), [dsep('test-tests/example.test.js')]], + [ + posix.join(testSrcDir, 'example.js'), + [posix.join(testTestDir, 'example.test.js')], + ], ]); assert.deepStrictEqual(importMap, expected); From 592c0b11d5daf3fca57c763982dbc5ed5bd44ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:25:00 -0300 Subject: [PATCH 08/24] debug: force sep --- .gitignore | 2 ++ test/unit/map-tests.test.ts | 57 ++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index ab8161a1..725ebea1 100755 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ node_modules .env .nyc_output /.temp +/test-src +/test-tests diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 2bab0e4d..02b26eaa 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -23,6 +23,22 @@ const removeDirSync = (dirPath: string) => { rmSync(dirPath, { recursive: true, force: true }); }; +const normalizeImportMap = ( + importMap: Map +): Map => { + const normalizedMap = new Map(); + for (const [key, value] of importMap) { + const normalizedKey = normalizePath(key); + const normalizedValue = value.map((v) => normalizePath(v)); + normalizedMap.set(normalizedKey, normalizedValue); + } + return normalizedMap; +}; + +const normalizePath = (filePath: string): string => { + return posix.normalize(filePath.replace(/\\/g, '/')); +}; + const testSrcDir = 'test-src'; const testTestDir = 'test-tests'; @@ -50,18 +66,18 @@ describe('mapTests', async () => { const importMap = await mapTests(testSrcDir, [testTestDir]); const expected = new Map([ [ - posix.join(testSrcDir, 'example.js'), + normalizePath(join(testSrcDir, 'example.js')), [ - posix.join(testTestDir, 'example.test.js'), - posix.join(testTestDir, 'exampleAbsolute.test.js'), + normalizePath(join(testTestDir, 'example.test.js')), + normalizePath(join(testTestDir, 'exampleAbsolute.test.js')), ], ], ]); - console.log(importMap); - console.log(expected); - - assert.deepStrictEqual(importMap, expected); + assert.deepStrictEqual( + normalizeImportMap(importMap), + normalizeImportMap(expected) + ); }); await it('should map single test file correctly', async () => { @@ -69,11 +85,32 @@ describe('mapTests', async () => { const importMap = await mapTests(testSrcDir, [singleTestFile]); const expected = new Map([ [ - posix.join(testSrcDir, 'example.js'), - [posix.join(testTestDir, 'example.test.js')], + normalizePath(join(testSrcDir, 'example.js')), + [normalizePath(singleTestFile)], + ], + ]); + + assert.deepStrictEqual( + normalizeImportMap(importMap), + normalizeImportMap(expected) + ); + }); + + await it('should include files that reference the normalized path directly', async () => { + const importMap = await mapTests(testSrcDir, [testTestDir]); + const expected = new Map([ + [ + normalizePath(join(testSrcDir, 'example.js')), + [ + normalizePath(join(testTestDir, 'example.test.js')), + normalizePath(join(testTestDir, 'exampleAbsolute.test.js')), + ], ], ]); - assert.deepStrictEqual(importMap, expected); + assert.deepStrictEqual( + normalizeImportMap(importMap), + normalizeImportMap(expected) + ); }); }); From 5c935612de887ce3243bf8f6e19fa7a791dcd18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:41:07 -0300 Subject: [PATCH 09/24] debug: normalize path --- test/unit/map-tests.test.ts | 89 +++++++++---------------------------- 1 file changed, 21 insertions(+), 68 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 02b26eaa..dce8323d 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -3,7 +3,7 @@ import { nodeVersion } from '../../src/helpers/get-runtime.js'; if (nodeVersion && nodeVersion < 14) process.exit(0); -import { join, posix } from 'node:path'; +import { join, normalize } from 'node:path'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; import { it } from '../../src/modules/it.js'; import { describe } from '../../src/modules/describe.js'; @@ -23,61 +23,35 @@ const removeDirSync = (dirPath: string) => { rmSync(dirPath, { recursive: true, force: true }); }; -const normalizeImportMap = ( - importMap: Map -): Map => { - const normalizedMap = new Map(); - for (const [key, value] of importMap) { - const normalizedKey = normalizePath(key); - const normalizedValue = value.map((v) => normalizePath(v)); - normalizedMap.set(normalizedKey, normalizedValue); - } - return normalizedMap; -}; - -const normalizePath = (filePath: string): string => { - return posix.normalize(filePath.replace(/\\/g, '/')); -}; - const testSrcDir = 'test-src'; const testTestDir = 'test-tests'; -beforeEach(() => { - createDirSync(testSrcDir); - createDirSync(testTestDir); - createFileSync(join(testSrcDir, 'example.js'), 'export const foo = 42;'); - createFileSync( - join(testTestDir, 'example.test.js'), - 'import { foo } from "../test-src/example.js";' - ); - createFileSync( - join(testTestDir, 'exampleAbsolute.test.js'), - `import { foo } from "${posix.join(testSrcDir, 'example.js')}";` - ); -}); +describe('mapTests', async () => { + beforeEach(() => { + createDirSync(testSrcDir); + createDirSync(testTestDir); + createFileSync(join(testSrcDir, 'example.js'), 'export const foo = 42;'); + createFileSync( + join(testTestDir, 'example.test.js'), + 'import { foo } from "../test-src/example.js";' + ); + }); -afterEach(() => { - removeDirSync(testSrcDir); - removeDirSync(testTestDir); -}); + afterEach(() => { + removeDirSync(testSrcDir); + removeDirSync(testTestDir); + }); -describe('mapTests', async () => { await it('should map test files to their corresponding source files', async () => { const importMap = await mapTests(testSrcDir, [testTestDir]); const expected = new Map([ [ - normalizePath(join(testSrcDir, 'example.js')), - [ - normalizePath(join(testTestDir, 'example.test.js')), - normalizePath(join(testTestDir, 'exampleAbsolute.test.js')), - ], + normalize('test-src/example.js'), + [normalize('test-tests/example.test.js')], ], ]); - assert.deepStrictEqual( - normalizeImportMap(importMap), - normalizeImportMap(expected) - ); + assert.deepStrictEqual(importMap, expected); }); await it('should map single test file correctly', async () => { @@ -85,32 +59,11 @@ describe('mapTests', async () => { const importMap = await mapTests(testSrcDir, [singleTestFile]); const expected = new Map([ [ - normalizePath(join(testSrcDir, 'example.js')), - [normalizePath(singleTestFile)], + normalize('test-src/example.js'), + [normalize('test-tests/example.test.js')], ], ]); - assert.deepStrictEqual( - normalizeImportMap(importMap), - normalizeImportMap(expected) - ); - }); - - await it('should include files that reference the normalized path directly', async () => { - const importMap = await mapTests(testSrcDir, [testTestDir]); - const expected = new Map([ - [ - normalizePath(join(testSrcDir, 'example.js')), - [ - normalizePath(join(testTestDir, 'example.test.js')), - normalizePath(join(testTestDir, 'exampleAbsolute.test.js')), - ], - ], - ]); - - assert.deepStrictEqual( - normalizeImportMap(importMap), - normalizeImportMap(expected) - ); + assert.deepStrictEqual(importMap, expected); }); }); From 656914038f78cd5fe07c1c3a4a642765ad6d847c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:49:35 -0300 Subject: [PATCH 10/24] debug: normalize path --- test/unit/map-tests.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index dce8323d..0df58192 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -46,11 +46,13 @@ describe('mapTests', async () => { const importMap = await mapTests(testSrcDir, [testTestDir]); const expected = new Map([ [ - normalize('test-src/example.js'), - [normalize('test-tests/example.test.js')], + normalize('test-src/example.js').replace(/\\/g, '/'), + [normalize('test-tests/example.test.js').replace(/\\/g, '/')], ], ]); + console.log('importMap:', Array.from(importMap.entries())); + assert.deepStrictEqual(importMap, expected); }); @@ -59,8 +61,8 @@ describe('mapTests', async () => { const importMap = await mapTests(testSrcDir, [singleTestFile]); const expected = new Map([ [ - normalize('test-src/example.js'), - [normalize('test-tests/example.test.js')], + normalize('test-src/example.js').replace(/\\/g, '/'), + [normalize('test-tests/example.test.js').replace(/\\/g, '/')], ], ]); From 9ca3883ac53f1959e25cdb581bae98e1f0427d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 02:57:09 -0300 Subject: [PATCH 11/24] debug: force sep --- src/services/map-tests.ts | 10 ++++------ test/unit/map-tests.test.ts | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index e337d589..671d3036 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -9,7 +9,8 @@ const normalizePath = (filePath: string) => filePath .replace(/(\.\/)/g, '') .replace(/^\.+/, '') - .replace(/[/\\]+/g, sep); + .replace(/[/\\]+/g, sep) + .replace(/\\/g, '/'); /* c8 ignore next */ export const mapTests = async (srcDir: string, testPaths: string[]) => { @@ -32,11 +33,8 @@ export const mapTests = async (srcDir: string, testPaths: string[]) => { const content = await readFile(testFile, 'utf-8'); for (const srcFile of allSrcFiles) { - const relativePath = normalizePath( - relative(dirname(testFile), srcFile).replace(/\\/g, '/') - ); - - const normalizedSrcFile = normalizePath(srcFile.replace(/\\/g, '/')); + const relativePath = normalizePath(relative(dirname(testFile), srcFile)); + const normalizedSrcFile = normalizePath(srcFile); /* c8 ignore start */ if ( diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 0df58192..7ea668ad 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -3,7 +3,7 @@ import { nodeVersion } from '../../src/helpers/get-runtime.js'; if (nodeVersion && nodeVersion < 14) process.exit(0); -import { join, normalize } from 'node:path'; +import { join, sep } from 'node:path'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; import { it } from '../../src/modules/it.js'; import { describe } from '../../src/modules/describe.js'; @@ -26,6 +26,13 @@ const removeDirSync = (dirPath: string) => { const testSrcDir = 'test-src'; const testTestDir = 'test-tests'; +const normalizePath = (filePath: string) => + filePath + .replace(/(\.\/)/g, '') + .replace(/^\.+/, '') + .replace(/[/\\]+/g, sep) + .replace(/\\/g, '/'); // Garantir uso de '/' para comparaçáes consistentes + describe('mapTests', async () => { beforeEach(() => { createDirSync(testSrcDir); @@ -44,25 +51,25 @@ describe('mapTests', async () => { await it('should map test files to their corresponding source files', async () => { const importMap = await mapTests(testSrcDir, [testTestDir]); + const expected = new Map([ [ - normalize('test-src/example.js').replace(/\\/g, '/'), - [normalize('test-tests/example.test.js').replace(/\\/g, '/')], + normalizePath('test-src/example.js'), + [normalizePath('test-tests/example.test.js')], ], ]); - console.log('importMap:', Array.from(importMap.entries())); - assert.deepStrictEqual(importMap, expected); }); await it('should map single test file correctly', async () => { const singleTestFile = join(testTestDir, 'example.test.js'); const importMap = await mapTests(testSrcDir, [singleTestFile]); + const expected = new Map([ [ - normalize('test-src/example.js').replace(/\\/g, '/'), - [normalize('test-tests/example.test.js').replace(/\\/g, '/')], + normalizePath('test-src/example.js'), + [normalizePath('test-tests/example.test.js')], ], ]); From bea6286e66072eee77775fc1996bfb4087ecd5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:06:15 -0300 Subject: [PATCH 12/24] chore: temporary ignore Windows --- test/unit/map-tests.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 7ea668ad..fc0c7c36 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -1,7 +1,9 @@ import process from 'node:process'; import { nodeVersion } from '../../src/helpers/get-runtime.js'; +import { isWindows } from '../../src/helpers/runner.js'; -if (nodeVersion && nodeVersion < 14) process.exit(0); +// TODO: Check why Windows doesn't get the files +if (isWindows || (nodeVersion && nodeVersion < 14)) process.exit(0); import { join, sep } from 'node:path'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; @@ -31,7 +33,7 @@ const normalizePath = (filePath: string) => .replace(/(\.\/)/g, '') .replace(/^\.+/, '') .replace(/[/\\]+/g, sep) - .replace(/\\/g, '/'); // Garantir uso de '/' para comparaçáes consistentes + .replace(/\\/g, '/'); describe('mapTests', async () => { beforeEach(() => { From 098b2422dea2ffcd3b6e10291efbfe81eac1c028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:12:27 -0300 Subject: [PATCH 13/24] debug: use only Windows CI --- .github/workflows/{ci_benchmark.yml => ci_benchmark.yml.bak} | 0 .../{ci_compatibility-bun.yml => ci_compatibility-bun.yml.bak} | 0 .../{ci_compatibility-deno.yml => ci_compatibility-deno.yml.bak} | 0 ...i_compatibility-nodejs.yml => ci_compatibility-nodejs.yml.bak} | 0 .../{ci_coverage-linux.yml => ci_coverage-linux.yml.bak} | 0 .../workflows/{ci_coverage-osx.yml => ci_coverage-osx.yml.bak} | 0 .../workflows/{ci_docs-website.yml => ci_docs-website.yml.bak} | 0 .github/workflows/{ci_lint.yml => ci_lint.yml.bak} | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{ci_benchmark.yml => ci_benchmark.yml.bak} (100%) rename .github/workflows/{ci_compatibility-bun.yml => ci_compatibility-bun.yml.bak} (100%) rename .github/workflows/{ci_compatibility-deno.yml => ci_compatibility-deno.yml.bak} (100%) rename .github/workflows/{ci_compatibility-nodejs.yml => ci_compatibility-nodejs.yml.bak} (100%) rename .github/workflows/{ci_coverage-linux.yml => ci_coverage-linux.yml.bak} (100%) rename .github/workflows/{ci_coverage-osx.yml => ci_coverage-osx.yml.bak} (100%) rename .github/workflows/{ci_docs-website.yml => ci_docs-website.yml.bak} (100%) rename .github/workflows/{ci_lint.yml => ci_lint.yml.bak} (100%) diff --git a/.github/workflows/ci_benchmark.yml b/.github/workflows/ci_benchmark.yml.bak similarity index 100% rename from .github/workflows/ci_benchmark.yml rename to .github/workflows/ci_benchmark.yml.bak diff --git a/.github/workflows/ci_compatibility-bun.yml b/.github/workflows/ci_compatibility-bun.yml.bak similarity index 100% rename from .github/workflows/ci_compatibility-bun.yml rename to .github/workflows/ci_compatibility-bun.yml.bak diff --git a/.github/workflows/ci_compatibility-deno.yml b/.github/workflows/ci_compatibility-deno.yml.bak similarity index 100% rename from .github/workflows/ci_compatibility-deno.yml rename to .github/workflows/ci_compatibility-deno.yml.bak diff --git a/.github/workflows/ci_compatibility-nodejs.yml b/.github/workflows/ci_compatibility-nodejs.yml.bak similarity index 100% rename from .github/workflows/ci_compatibility-nodejs.yml rename to .github/workflows/ci_compatibility-nodejs.yml.bak diff --git a/.github/workflows/ci_coverage-linux.yml b/.github/workflows/ci_coverage-linux.yml.bak similarity index 100% rename from .github/workflows/ci_coverage-linux.yml rename to .github/workflows/ci_coverage-linux.yml.bak diff --git a/.github/workflows/ci_coverage-osx.yml b/.github/workflows/ci_coverage-osx.yml.bak similarity index 100% rename from .github/workflows/ci_coverage-osx.yml rename to .github/workflows/ci_coverage-osx.yml.bak diff --git a/.github/workflows/ci_docs-website.yml b/.github/workflows/ci_docs-website.yml.bak similarity index 100% rename from .github/workflows/ci_docs-website.yml rename to .github/workflows/ci_docs-website.yml.bak diff --git a/.github/workflows/ci_lint.yml b/.github/workflows/ci_lint.yml.bak similarity index 100% rename from .github/workflows/ci_lint.yml rename to .github/workflows/ci_lint.yml.bak From 62be6551a8c7e83a39b2bf0aa1727682965b72a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:13:46 -0300 Subject: [PATCH 14/24] debug: use only Windows CI --- .github/workflows/ci_coverage-windows.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci_coverage-windows.yml b/.github/workflows/ci_coverage-windows.yml index 869a04ec..77e4a8b0 100644 --- a/.github/workflows/ci_coverage-windows.yml +++ b/.github/workflows/ci_coverage-windows.yml @@ -117,9 +117,9 @@ jobs: - name: πŸ§ͺ Checking for Coverage run: npm run test:c8:parallel:options - - name: β˜”οΈ Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - flags: windows-parallel-options - name: codecov-umbrella-windows-parallel-options + # - name: β˜”οΈ Upload coverage reports to Codecov + # uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # flags: windows-parallel-options + # name: codecov-umbrella-windows-parallel-options From 8e6c49a1db6061cd2fe33d5a5e7cd9403ad13db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:15:30 -0300 Subject: [PATCH 15/24] debug: use only Windows CI --- .github/workflows/ci_coverage-windows.yml | 176 +++++++++++----------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/.github/workflows/ci_coverage-windows.yml b/.github/workflows/ci_coverage-windows.yml index 77e4a8b0..035bea75 100644 --- a/.github/workflows/ci_coverage-windows.yml +++ b/.github/workflows/ci_coverage-windows.yml @@ -8,34 +8,34 @@ on: workflow_dispatch: jobs: - sequential: - runs-on: windows-latest - timeout-minutes: 5 - strategy: - fail-fast: false - name: Windows (Sequential) - steps: - - name: βž• Actions - Checkout - uses: actions/checkout@v4 - - - name: βž• Actions - Setup NodeJS - uses: actions/setup-node@v4 - with: - node-version: '22.x' - cache: 'npm' - - - name: πŸ“¦ Installing Dependencies - run: npm ci - - - name: πŸ§ͺ Checking for Coverage - run: npm run test:c8:sequential - - - name: β˜”οΈ Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - flags: windows-sequential - name: codecov-umbrella-windows-sequential + # sequential: + # runs-on: windows-latest + # timeout-minutes: 5 + # strategy: + # fail-fast: false + # name: Windows (Sequential) + # steps: + # - name: βž• Actions - Checkout + # uses: actions/checkout@v4 + + # - name: βž• Actions - Setup NodeJS + # uses: actions/setup-node@v4 + # with: + # node-version: '22.x' + # cache: 'npm' + + # - name: πŸ“¦ Installing Dependencies + # run: npm ci + + # - name: πŸ§ͺ Checking for Coverage + # run: npm run test:c8:sequential + + # - name: β˜”οΈ Upload coverage reports to Codecov + # uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # flags: windows-sequential + # name: codecov-umbrella-windows-sequential sequential-options: runs-on: windows-latest @@ -59,67 +59,67 @@ jobs: - name: πŸ§ͺ Checking for Coverage run: npm run test:c8:sequential:options - - name: β˜”οΈ Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - flags: windows-sequential-options - name: codecov-umbrella-windows-sequential-options - - parallel: - runs-on: windows-latest - timeout-minutes: 5 - strategy: - fail-fast: false - name: Windows (Parallel) - steps: - - name: βž• Actions - Checkout - uses: actions/checkout@v4 - - - name: βž• Actions - Setup NodeJS - uses: actions/setup-node@v4 - with: - node-version: '22.x' - cache: 'npm' - - - name: πŸ“¦ Installing Dependencies - run: npm ci - - - name: πŸ§ͺ Checking for Coverage - run: npm run test:c8:parallel - - - name: β˜”οΈ Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - flags: windows-parallel - name: codecov-umbrella-windows-parallel - - parallel-options: - runs-on: windows-latest - timeout-minutes: 5 - strategy: - fail-fast: false - name: Windows (Parallel & Options) - steps: - - name: βž• Actions - Checkout - uses: actions/checkout@v4 - - - name: βž• Actions - Setup NodeJS - uses: actions/setup-node@v4 - with: - node-version: '22.x' - cache: 'npm' - - - name: πŸ“¦ Installing Dependencies - run: npm ci - - - name: πŸ§ͺ Checking for Coverage - run: npm run test:c8:parallel:options - # - name: β˜”οΈ Upload coverage reports to Codecov # uses: codecov/codecov-action@v4 # with: # token: ${{ secrets.CODECOV_TOKEN }} - # flags: windows-parallel-options - # name: codecov-umbrella-windows-parallel-options + # flags: windows-sequential-options + # name: codecov-umbrella-windows-sequential-options + + # parallel: + # runs-on: windows-latest + # timeout-minutes: 5 + # strategy: + # fail-fast: false + # name: Windows (Parallel) + # steps: + # - name: βž• Actions - Checkout + # uses: actions/checkout@v4 + + # - name: βž• Actions - Setup NodeJS + # uses: actions/setup-node@v4 + # with: + # node-version: '22.x' + # cache: 'npm' + + # - name: πŸ“¦ Installing Dependencies + # run: npm ci + + # - name: πŸ§ͺ Checking for Coverage + # run: npm run test:c8:parallel + + # - name: β˜”οΈ Upload coverage reports to Codecov + # uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # flags: windows-parallel + # name: codecov-umbrella-windows-parallel + + # parallel-options: + # runs-on: windows-latest + # timeout-minutes: 5 + # strategy: + # fail-fast: false + # name: Windows (Parallel & Options) + # steps: + # - name: βž• Actions - Checkout + # uses: actions/checkout@v4 + + # - name: βž• Actions - Setup NodeJS + # uses: actions/setup-node@v4 + # with: + # node-version: '22.x' + # cache: 'npm' + + # - name: πŸ“¦ Installing Dependencies + # run: npm ci + + # - name: πŸ§ͺ Checking for Coverage + # run: npm run test:c8:parallel:options + + # - name: β˜”οΈ Upload coverage reports to Codecov + # uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # flags: windows-parallel-options + # name: codecov-umbrella-windows-parallel-options From 6b3a1d1dc3db5a8b82f44a33db72d42abfb52622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:18:41 -0300 Subject: [PATCH 16/24] debug: use only Windows CI --- .github/workflows/ci_coverage-windows.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_coverage-windows.yml b/.github/workflows/ci_coverage-windows.yml index 035bea75..4f2c7b39 100644 --- a/.github/workflows/ci_coverage-windows.yml +++ b/.github/workflows/ci_coverage-windows.yml @@ -57,7 +57,8 @@ jobs: run: npm ci - name: πŸ§ͺ Checking for Coverage - run: npm run test:c8:sequential:options + # run: npm run test:c8:sequential:options + run: npm run test:sequential -- --debug --filter="map-tests" # - name: β˜”οΈ Upload coverage reports to Codecov # uses: codecov/codecov-action@v4 From 1da26ba839b59524e5368d656730bd854f8e5bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:22:30 -0300 Subject: [PATCH 17/24] debug: use only Windows CI --- .github/workflows/ci_coverage-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_coverage-windows.yml b/.github/workflows/ci_coverage-windows.yml index 4f2c7b39..445ca6ab 100644 --- a/.github/workflows/ci_coverage-windows.yml +++ b/.github/workflows/ci_coverage-windows.yml @@ -58,7 +58,7 @@ jobs: - name: πŸ§ͺ Checking for Coverage # run: npm run test:c8:sequential:options - run: npm run test:sequential -- --debug --filter="map-tests" + run: npx tsx src/bin/index.ts --debug test/unit/map-tests.test.ts # - name: β˜”οΈ Upload coverage reports to Codecov # uses: codecov/codecov-action@v4 From 537fa928a5e6edbc12cb913359d1cf9f1be8d55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:29:37 -0300 Subject: [PATCH 18/24] debug --- src/services/map-tests.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index 671d3036..64a06923 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -29,6 +29,8 @@ export const mapTests = async (srcDir: string, testPaths: string[]) => { allTestFiles.push(testPath); } + console.log('allTestFiles:', allTestFiles); + for (const testFile of allTestFiles) { const content = await readFile(testFile, 'utf-8'); @@ -36,6 +38,9 @@ export const mapTests = async (srcDir: string, testPaths: string[]) => { const relativePath = normalizePath(relative(dirname(testFile), srcFile)); const normalizedSrcFile = normalizePath(srcFile); + console.log('relativePath:', relativePath); + console.log('normalizedSrcFile:', normalizedSrcFile); + /* c8 ignore start */ if ( content.includes(relativePath.replace(filter, '')) || From 532e505e703fe837127ec78ff5e42b07320aa0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:30:39 -0300 Subject: [PATCH 19/24] debug --- test/unit/map-tests.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index fc0c7c36..58f62160 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -1,9 +1,7 @@ import process from 'node:process'; import { nodeVersion } from '../../src/helpers/get-runtime.js'; -import { isWindows } from '../../src/helpers/runner.js'; -// TODO: Check why Windows doesn't get the files -if (isWindows || (nodeVersion && nodeVersion < 14)) process.exit(0); +if (nodeVersion && nodeVersion < 14) process.exit(0); import { join, sep } from 'node:path'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; From b904c2ef05995d9a8b1532682647d916d3380021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:32:53 -0300 Subject: [PATCH 20/24] debug --- test/unit/map-tests.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 58f62160..a632c9bf 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -59,7 +59,7 @@ describe('mapTests', async () => { ], ]); - assert.deepStrictEqual(importMap, expected); + assert.deepStrictEqual(Array.from(importMap), Array.from(expected)); }); await it('should map single test file correctly', async () => { @@ -73,6 +73,6 @@ describe('mapTests', async () => { ], ]); - assert.deepStrictEqual(importMap, expected); + assert.deepStrictEqual(Array.from(importMap), Array.from(expected)); }); }); From 0bcf91277dd5bae7fd2b64581f57ba2bb079505a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:36:50 -0300 Subject: [PATCH 21/24] debug --- src/services/map-tests.ts | 3 +-- test/unit/map-tests.test.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index 64a06923..b173fa9a 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -9,8 +9,7 @@ const normalizePath = (filePath: string) => filePath .replace(/(\.\/)/g, '') .replace(/^\.+/, '') - .replace(/[/\\]+/g, sep) - .replace(/\\/g, '/'); + .replace(/[/\\]+/g, sep); /* c8 ignore next */ export const mapTests = async (srcDir: string, testPaths: string[]) => { diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index a632c9bf..014a3fec 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -30,8 +30,7 @@ const normalizePath = (filePath: string) => filePath .replace(/(\.\/)/g, '') .replace(/^\.+/, '') - .replace(/[/\\]+/g, sep) - .replace(/\\/g, '/'); + .replace(/[/\\]+/g, sep); describe('mapTests', async () => { beforeEach(() => { From dbbd4ab2f7f5131ca44f4aeaa14d1d4597dd6297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:38:42 -0300 Subject: [PATCH 22/24] debug --- src/services/map-tests.ts | 3 ++- test/unit/map-tests.test.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index b173fa9a..64a06923 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -9,7 +9,8 @@ const normalizePath = (filePath: string) => filePath .replace(/(\.\/)/g, '') .replace(/^\.+/, '') - .replace(/[/\\]+/g, sep); + .replace(/[/\\]+/g, sep) + .replace(/\\/g, '/'); /* c8 ignore next */ export const mapTests = async (srcDir: string, testPaths: string[]) => { diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index 014a3fec..a632c9bf 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -30,7 +30,8 @@ const normalizePath = (filePath: string) => filePath .replace(/(\.\/)/g, '') .replace(/^\.+/, '') - .replace(/[/\\]+/g, sep); + .replace(/[/\\]+/g, sep) + .replace(/\\/g, '/'); describe('mapTests', async () => { beforeEach(() => { From 0a2aa7778e53c02e59d87b1f4b9663969193742f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:41:06 -0300 Subject: [PATCH 23/24] debug --- src/services/map-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index 64a06923..c9311d13 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -49,7 +49,7 @@ export const mapTests = async (srcDir: string, testPaths: string[]) => { if (!importMap.has(normalizedSrcFile)) importMap.set(normalizedSrcFile, []); - importMap.get(normalizedSrcFile)!.push(testFile); + importMap.get(normalizedSrcFile)!.push(normalizePath(testFile)); } /* c8 ignore stop */ } From 7b90cb7a39d8d5a199a71894121c3acf4442a9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sat, 15 Jun 2024 03:52:23 -0300 Subject: [PATCH 24/24] chore: rollback debug changes --- ...{ci_benchmark.yml.bak => ci_benchmark.yml} | 0 ...y-bun.yml.bak => ci_compatibility-bun.yml} | 0 ...deno.yml.bak => ci_compatibility-deno.yml} | 0 ...js.yml.bak => ci_compatibility-nodejs.yml} | 0 ...ge-linux.yml.bak => ci_coverage-linux.yml} | 0 ...verage-osx.yml.bak => ci_coverage-osx.yml} | 0 .github/workflows/ci_coverage-windows.yml | 189 +++++++++--------- ...cs-website.yml.bak => ci_docs-website.yml} | 0 .../{ci_lint.yml.bak => ci_lint.yml} | 0 src/bin/index.ts | 12 +- src/services/map-tests.ts | 7 +- test/unit/map-tests.test.ts | 11 +- test/unit/watch.test.ts | 22 +- 13 files changed, 115 insertions(+), 126 deletions(-) rename .github/workflows/{ci_benchmark.yml.bak => ci_benchmark.yml} (100%) rename .github/workflows/{ci_compatibility-bun.yml.bak => ci_compatibility-bun.yml} (100%) rename .github/workflows/{ci_compatibility-deno.yml.bak => ci_compatibility-deno.yml} (100%) rename .github/workflows/{ci_compatibility-nodejs.yml.bak => ci_compatibility-nodejs.yml} (100%) rename .github/workflows/{ci_coverage-linux.yml.bak => ci_coverage-linux.yml} (100%) rename .github/workflows/{ci_coverage-osx.yml.bak => ci_coverage-osx.yml} (100%) rename .github/workflows/{ci_docs-website.yml.bak => ci_docs-website.yml} (100%) rename .github/workflows/{ci_lint.yml.bak => ci_lint.yml} (100%) diff --git a/.github/workflows/ci_benchmark.yml.bak b/.github/workflows/ci_benchmark.yml similarity index 100% rename from .github/workflows/ci_benchmark.yml.bak rename to .github/workflows/ci_benchmark.yml diff --git a/.github/workflows/ci_compatibility-bun.yml.bak b/.github/workflows/ci_compatibility-bun.yml similarity index 100% rename from .github/workflows/ci_compatibility-bun.yml.bak rename to .github/workflows/ci_compatibility-bun.yml diff --git a/.github/workflows/ci_compatibility-deno.yml.bak b/.github/workflows/ci_compatibility-deno.yml similarity index 100% rename from .github/workflows/ci_compatibility-deno.yml.bak rename to .github/workflows/ci_compatibility-deno.yml diff --git a/.github/workflows/ci_compatibility-nodejs.yml.bak b/.github/workflows/ci_compatibility-nodejs.yml similarity index 100% rename from .github/workflows/ci_compatibility-nodejs.yml.bak rename to .github/workflows/ci_compatibility-nodejs.yml diff --git a/.github/workflows/ci_coverage-linux.yml.bak b/.github/workflows/ci_coverage-linux.yml similarity index 100% rename from .github/workflows/ci_coverage-linux.yml.bak rename to .github/workflows/ci_coverage-linux.yml diff --git a/.github/workflows/ci_coverage-osx.yml.bak b/.github/workflows/ci_coverage-osx.yml similarity index 100% rename from .github/workflows/ci_coverage-osx.yml.bak rename to .github/workflows/ci_coverage-osx.yml diff --git a/.github/workflows/ci_coverage-windows.yml b/.github/workflows/ci_coverage-windows.yml index 445ca6ab..869a04ec 100644 --- a/.github/workflows/ci_coverage-windows.yml +++ b/.github/workflows/ci_coverage-windows.yml @@ -8,34 +8,34 @@ on: workflow_dispatch: jobs: - # sequential: - # runs-on: windows-latest - # timeout-minutes: 5 - # strategy: - # fail-fast: false - # name: Windows (Sequential) - # steps: - # - name: βž• Actions - Checkout - # uses: actions/checkout@v4 - - # - name: βž• Actions - Setup NodeJS - # uses: actions/setup-node@v4 - # with: - # node-version: '22.x' - # cache: 'npm' - - # - name: πŸ“¦ Installing Dependencies - # run: npm ci - - # - name: πŸ§ͺ Checking for Coverage - # run: npm run test:c8:sequential - - # - name: β˜”οΈ Upload coverage reports to Codecov - # uses: codecov/codecov-action@v4 - # with: - # token: ${{ secrets.CODECOV_TOKEN }} - # flags: windows-sequential - # name: codecov-umbrella-windows-sequential + sequential: + runs-on: windows-latest + timeout-minutes: 5 + strategy: + fail-fast: false + name: Windows (Sequential) + steps: + - name: βž• Actions - Checkout + uses: actions/checkout@v4 + + - name: βž• Actions - Setup NodeJS + uses: actions/setup-node@v4 + with: + node-version: '22.x' + cache: 'npm' + + - name: πŸ“¦ Installing Dependencies + run: npm ci + + - name: πŸ§ͺ Checking for Coverage + run: npm run test:c8:sequential + + - name: β˜”οΈ Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: windows-sequential + name: codecov-umbrella-windows-sequential sequential-options: runs-on: windows-latest @@ -57,70 +57,69 @@ jobs: run: npm ci - name: πŸ§ͺ Checking for Coverage - # run: npm run test:c8:sequential:options - run: npx tsx src/bin/index.ts --debug test/unit/map-tests.test.ts - - # - name: β˜”οΈ Upload coverage reports to Codecov - # uses: codecov/codecov-action@v4 - # with: - # token: ${{ secrets.CODECOV_TOKEN }} - # flags: windows-sequential-options - # name: codecov-umbrella-windows-sequential-options - - # parallel: - # runs-on: windows-latest - # timeout-minutes: 5 - # strategy: - # fail-fast: false - # name: Windows (Parallel) - # steps: - # - name: βž• Actions - Checkout - # uses: actions/checkout@v4 - - # - name: βž• Actions - Setup NodeJS - # uses: actions/setup-node@v4 - # with: - # node-version: '22.x' - # cache: 'npm' - - # - name: πŸ“¦ Installing Dependencies - # run: npm ci - - # - name: πŸ§ͺ Checking for Coverage - # run: npm run test:c8:parallel - - # - name: β˜”οΈ Upload coverage reports to Codecov - # uses: codecov/codecov-action@v4 - # with: - # token: ${{ secrets.CODECOV_TOKEN }} - # flags: windows-parallel - # name: codecov-umbrella-windows-parallel - - # parallel-options: - # runs-on: windows-latest - # timeout-minutes: 5 - # strategy: - # fail-fast: false - # name: Windows (Parallel & Options) - # steps: - # - name: βž• Actions - Checkout - # uses: actions/checkout@v4 - - # - name: βž• Actions - Setup NodeJS - # uses: actions/setup-node@v4 - # with: - # node-version: '22.x' - # cache: 'npm' - - # - name: πŸ“¦ Installing Dependencies - # run: npm ci - - # - name: πŸ§ͺ Checking for Coverage - # run: npm run test:c8:parallel:options - - # - name: β˜”οΈ Upload coverage reports to Codecov - # uses: codecov/codecov-action@v4 - # with: - # token: ${{ secrets.CODECOV_TOKEN }} - # flags: windows-parallel-options - # name: codecov-umbrella-windows-parallel-options + run: npm run test:c8:sequential:options + + - name: β˜”οΈ Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: windows-sequential-options + name: codecov-umbrella-windows-sequential-options + + parallel: + runs-on: windows-latest + timeout-minutes: 5 + strategy: + fail-fast: false + name: Windows (Parallel) + steps: + - name: βž• Actions - Checkout + uses: actions/checkout@v4 + + - name: βž• Actions - Setup NodeJS + uses: actions/setup-node@v4 + with: + node-version: '22.x' + cache: 'npm' + + - name: πŸ“¦ Installing Dependencies + run: npm ci + + - name: πŸ§ͺ Checking for Coverage + run: npm run test:c8:parallel + + - name: β˜”οΈ Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: windows-parallel + name: codecov-umbrella-windows-parallel + + parallel-options: + runs-on: windows-latest + timeout-minutes: 5 + strategy: + fail-fast: false + name: Windows (Parallel & Options) + steps: + - name: βž• Actions - Checkout + uses: actions/checkout@v4 + + - name: βž• Actions - Setup NodeJS + uses: actions/setup-node@v4 + with: + node-version: '22.x' + cache: 'npm' + + - name: πŸ“¦ Installing Dependencies + run: npm ci + + - name: πŸ§ͺ Checking for Coverage + run: npm run test:c8:parallel:options + + - name: β˜”οΈ Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: windows-parallel-options + name: codecov-umbrella-windows-parallel-options diff --git a/.github/workflows/ci_docs-website.yml.bak b/.github/workflows/ci_docs-website.yml similarity index 100% rename from .github/workflows/ci_docs-website.yml.bak rename to .github/workflows/ci_docs-website.yml diff --git a/.github/workflows/ci_lint.yml.bak b/.github/workflows/ci_lint.yml similarity index 100% rename from .github/workflows/ci_lint.yml.bak rename to .github/workflows/ci_lint.yml diff --git a/src/bin/index.ts b/src/bin/index.ts index 81cebd96..8ae4651a 100644 --- a/src/bin/index.ts +++ b/src/bin/index.ts @@ -14,7 +14,7 @@ import { platformIsValid } from '../helpers/get-runtime.js'; import { format } from '../helpers/format.js'; import { write } from '../helpers/logs.js'; import { hr } from '../helpers/hr.js'; -import { mapTests } from '../services/map-tests.js'; +import { mapTests, normalizePath } from '../services/map-tests.js'; import { watch } from '../services/watch.js'; import { poku } from '../modules/poku.js'; import { kill } from '../modules/processes.js'; @@ -112,6 +112,7 @@ import type { Configs } from '../@types/poku.js'; if (watchMode) { const executing = new Set(); const interval = Number(getArg('watch-interval')) || 1500; + const resultsClear = () => { fileResults.success.clear(); fileResults.fail.clear(); @@ -123,17 +124,18 @@ import type { Configs } from '../@types/poku.js'; Array.from(mappedTests.keys()).forEach((mappedTest) => { watch(mappedTest, (file, event) => { if (event === 'change') { - if (executing.has(file)) return; + const filePath = normalizePath(file); + if (executing.has(filePath)) return; - executing.add(file); + executing.add(filePath); resultsClear(); - const tests = mappedTests.get(file); + const tests = mappedTests.get(filePath); if (!tests) return; poku(tests, options).then(() => { setTimeout(() => { - executing.delete(file); + executing.delete(filePath); }, interval); }); } diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index c9311d13..83325372 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -5,7 +5,7 @@ import { listFiles } from '../modules/list-files.js'; const filter = /\.(js|cjs|mjs|ts|cts|mts)$/; -const normalizePath = (filePath: string) => +export const normalizePath = (filePath: string) => filePath .replace(/(\.\/)/g, '') .replace(/^\.+/, '') @@ -29,8 +29,6 @@ export const mapTests = async (srcDir: string, testPaths: string[]) => { allTestFiles.push(testPath); } - console.log('allTestFiles:', allTestFiles); - for (const testFile of allTestFiles) { const content = await readFile(testFile, 'utf-8'); @@ -38,9 +36,6 @@ export const mapTests = async (srcDir: string, testPaths: string[]) => { const relativePath = normalizePath(relative(dirname(testFile), srcFile)); const normalizedSrcFile = normalizePath(srcFile); - console.log('relativePath:', relativePath); - console.log('normalizedSrcFile:', normalizedSrcFile); - /* c8 ignore start */ if ( content.includes(relativePath.replace(filter, '')) || diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index a632c9bf..f71408e6 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -3,13 +3,13 @@ import { nodeVersion } from '../../src/helpers/get-runtime.js'; if (nodeVersion && nodeVersion < 14) process.exit(0); -import { join, sep } from 'node:path'; +import { join } from 'node:path'; import { writeFileSync, mkdirSync, rmSync } from 'node:fs'; import { it } from '../../src/modules/it.js'; import { describe } from '../../src/modules/describe.js'; import { beforeEach, afterEach } from '../../src/modules/each.js'; import { assert } from '../../src/modules/assert.js'; -import { mapTests } from '../../src/services/map-tests.js'; +import { mapTests, normalizePath } from '../../src/services/map-tests.js'; const createFileSync = (filePath: string, content: string) => { writeFileSync(filePath, content); @@ -26,13 +26,6 @@ const removeDirSync = (dirPath: string) => { const testSrcDir = 'test-src'; const testTestDir = 'test-tests'; -const normalizePath = (filePath: string) => - filePath - .replace(/(\.\/)/g, '') - .replace(/^\.+/, '') - .replace(/[/\\]+/g, sep) - .replace(/\\/g, '/'); - describe('mapTests', async () => { beforeEach(() => { createDirSync(testSrcDir); diff --git a/test/unit/watch.test.ts b/test/unit/watch.test.ts index 7188b837..aac52771 100644 --- a/test/unit/watch.test.ts +++ b/test/unit/watch.test.ts @@ -55,7 +55,7 @@ describe('Watcher Service', async () => { setTimeout(() => { fs.writeFileSync(filePath, 'export default { updated: true };'); // update resolve(undefined); - }, 1000); + }, 250); }); return await new Promise((resolve) => { @@ -73,7 +73,7 @@ describe('Watcher Service', async () => { watcher.stop(); resolve(undefined); - }, 1000); + }, 250); }); }); @@ -92,7 +92,7 @@ describe('Watcher Service', async () => { setTimeout(() => { fs.writeFileSync(newFilePath, 'export default {};'); // update resolve(undefined); - }, 1000); + }, 250); }); return await new Promise((resolve) => { @@ -110,7 +110,7 @@ describe('Watcher Service', async () => { watcher.stop(); resolve(undefined); - }, 1000); + }, 250); }); }); @@ -129,7 +129,7 @@ describe('Watcher Service', async () => { 'Callback should not be called after watcher is stopped' ); resolve(undefined); - }, 1000); + }, 250); }); }); @@ -149,7 +149,7 @@ describe('Watcher Service', async () => { setTimeout(() => { fs.writeFileSync(newFilePath, 'export default {};'); // update resolve(undefined); - }, 1000); + }, 250); }); return new Promise((resolve) => { @@ -167,7 +167,7 @@ describe('Watcher Service', async () => { watcher.stop(); resolve(undefined); - }, 1000); + }, 250); }); }); @@ -187,7 +187,7 @@ describe('Watcher Service', async () => { setTimeout(() => { fs.writeFileSync(newNestedFilePath, 'export default {};'); // update resolve(undefined); - }, 1000); + }, 250); }); return await new Promise((resolve) => { @@ -206,7 +206,7 @@ describe('Watcher Service', async () => { watcher.stop(); resolve(undefined); - }, 1000); + }, 250); }); }); @@ -224,7 +224,7 @@ describe('Watcher Service', async () => { setTimeout(() => { fs.writeFileSync(filePath, 'export default {};'); resolve(undefined); - }, 1000); + }, 250); }); return await new Promise((resolve) => { @@ -242,7 +242,7 @@ describe('Watcher Service', async () => { watcher.stop(); resolve(undefined); - }, 1000); + }, 250); }); }); });