Skip to content

Commit

Permalink
chore(import): fix failing tests on windows os (#3629)
Browse files Browse the repository at this point in the history
  • Loading branch information
amorscher committed May 8, 2023
1 parent 722d42c commit 9d27d85
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ jobs:
runs-on: windows-latest
env:
LERNA_OS_TYPE: windows
# Set the temp directory to a short dir without username in it otherwise import command specs have a problem because of different paths on windows agents
TEMP: C:\temp
TMP: C:\temp
steps:
- uses: actions/checkout@v3

Expand All @@ -112,12 +115,10 @@ jobs:
# From old maintainer regarding integration tests: "import is NOT TESTED in windows because pain and suffering"
run: |
pids=()
npx nx run integration:integration --ci --maxWorkers=2 --testPathIgnorePatterns=lerna-import.spec.ts &
npx nx run integration:integration --ci --maxWorkers=2 &
pids+=($!)
# Ignored specs currently failing on windows
# TODO: investigate why
npx nx run-many -t test --parallel=3 --ci --maxWorkers=2 --testTimeout=60000 --testPathIgnorePatterns=import-command.spec.ts &
npx nx run-many -t test --parallel=3 --ci --maxWorkers=2 --testTimeout=60000 &
pids+=($!)
Expand All @@ -138,6 +139,9 @@ jobs:
agent: [1, 2, 3, 4]
env:
LERNA_OS_TYPE: windows
# Set the temp directory to a short dir without containing username, otherwise import command specs have a problem because of different paths on windows agents
TEMP: C:\temp
TMP: C:\temp
steps:
- uses: actions/checkout@v3

Expand Down
8 changes: 8 additions & 0 deletions libs/commands/import/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class ImportCommand extends Command {
const lernaRootRelativeToGitRoot = path.relative(gitRepoRoot, this.project.rootPath);
this.targetDirRelativeToGitRoot = path.join(lernaRootRelativeToGitRoot, targetDir);

//if the target directory is not in the Git root
if (this.targetDirRelativeToGitRoot.startsWith("..")) {
throw new ValidationError(
"ENOTINREPO",
`Project root ${this.project.rootPath} is not a subdirectory of git root ${gitRepoRoot}`
);
}

if (fs.existsSync(path.resolve(this.project.rootPath, targetDir))) {
throw new ValidationError("EEXISTS", `Target directory already exists "${targetDir}"`);
}
Expand Down
14 changes: 14 additions & 0 deletions libs/commands/import/src/lib/import-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ describe("ImportCommand", () => {
await expect(command).rejects.toThrow(`Target directory already exists "${relativePath}"`);
});

it("errors if projectDir is not in repository", async () => {
const [testDir, externalDir] = await initBasicFixtures();
//create a symlinked project
const symlinkedLernaPath = path.join(testDir, "symlink");
const linkedProject = await initFixture("basic");
fs.symlinkSync(linkedProject, symlinkedLernaPath, "dir");

const command = lernaImport(symlinkedLernaPath)(externalDir);

await expect(command).rejects.toThrow(
`Project root ${symlinkedLernaPath} is not a subdirectory of git root`
);
});

it("infers correct target directory given packages glob", async () => {
const [testDir, externalDir] = await initBasicFixtures();
const targetDir = path.join(testDir, "pkg", path.basename(externalDir));
Expand Down

0 comments on commit 9d27d85

Please sign in to comment.