diff --git a/test/cypress/docker/find/find.js b/test/cypress/docker/find/find.js index e20f3b80a..ae463f333 100644 --- a/test/cypress/docker/find/find.js +++ b/test/cypress/docker/find/find.js @@ -1,6 +1,9 @@ import { execSync } from 'child_process'; import { findImports } from './find-imports.js'; import { getModules } from './get-modules.js'; +const E2E_PATH = 'test/cypress/integration'; +const FINDED_PATHS = ['src', E2E_PATH]; + function getGitDiff(options) { const TARGET_BRANCH = options[2] || 'dev'; const diff = execSync(`git diff --name-only origin/${TARGET_BRANCH}`, { @@ -10,21 +13,22 @@ function getGitDiff(options) { } async function getChangedModules() { - const FINDED_PATHS = ['src', 'test/cypress/integration']; let changedModules = new Set(); const changes = getGitDiff(process.argv); for (const change of changes) { if (!FINDED_PATHS.some((prefix) => change.startsWith(prefix))) return ''; - changedModules = new Set([ + const changedArray = [ ...changedModules, ...new Set(getModules(await findImports(change))), - ]); + ]; + if (change.startsWith(E2E_PATH)) changedArray.push(change); + changedModules = new Set(changedArray); } return [...changedModules].join(' '); } getChangedModules() - .then((modules) => console.log(modules)) // return + .then((modules) => console.log(modules)) // is return .catch((e) => { console.error(e); process.exit(1); diff --git a/test/cypress/docker/find/resolve-import-path.js b/test/cypress/docker/find/resolve-import-path.js index 53ee6eea7..b52dfa065 100644 --- a/test/cypress/docker/find/resolve-import-path.js +++ b/test/cypress/docker/find/resolve-import-path.js @@ -1,20 +1,33 @@ import path from 'path'; const rootDir = process.cwd(); +import config from '../../../../jsconfig.json' with { type: 'json' }; +const { paths, baseUrl } = config.compilerOptions; function resolveImportPath(importPath, fileBase) { - const fileDir = path.dirname(fileBase); - if (!importPath) return null; - + importPath = jsConfigPaths(importPath); + const fileDir = path.dirname(fileBase); if (importPath.startsWith('.') || importPath.startsWith('/')) { return path.relative(rootDir, path.resolve(fileDir, importPath)); } return importPath; } - function toRelative(file) { return path.relative(rootDir, file); } +function jsConfigPaths(importPath) { + for (const [aliasPattern, [target]] of Object.entries(paths)) { + const alias = aliasPattern.replace('/*', ''); + const targetBase = target.replace('/*', ''); + + if (importPath.startsWith(alias)) { + const rest = importPath.slice(alias.length); + return path.resolve(baseUrl, targetBase + rest); + } + } + return importPath; +} + export { resolveImportPath, toRelative };