Skip to content

Commit 7d1d14f

Browse files
robertIsaacFrozenPandaz
authored andcommitted
cleanup(js): fix test cases on windows (#27300)
## Current Behavior running `nx test js` fail on windows ## Expected Behavior running `nx test js` succeed ## side notes 1. I was skipping `packages/js/src/plugins/typescript/plugin.spec.ts` because it makes all tests fail, and even in wsl it's very flaky, it fail 90% of the times, but I couldn't figure out why I think it's worth looking at from someone with more experience with the repo 2. for some of the cases that I fixed I'm not sure if I should change the code to always return `/` or should change the test to adapt `/` in linux and `\` in windows, so please if I mistaken one of them let me know and I will do it the other way around but I believe it should be fine since in windows `foo/bar` does work as a path still (cherry picked from commit 69c989e)
1 parent f57780d commit 7d1d14f

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

packages/js/src/executors/tsc/tsc.impl.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as ts from 'typescript';
2-
import { ExecutorContext, isDaemonEnabled, output } from '@nx/devkit';
2+
import {
3+
ExecutorContext,
4+
isDaemonEnabled,
5+
joinPathFragments,
6+
output,
7+
} from '@nx/devkit';
38
import type { TypeScriptCompilationOptions } from '@nx/workspace/src/utilities/typescript/compilation';
49
import { CopyAssetsHandler } from '../../utils/assets/copy-assets-handler';
510
import { checkDependencies } from '../../utils/check-dependencies';
@@ -41,11 +46,11 @@ export function createTypeScriptCompilationOptions(
4146
context: ExecutorContext
4247
): TypeScriptCompilationOptions {
4348
return {
44-
outputPath: normalizedOptions.outputPath,
49+
outputPath: joinPathFragments(normalizedOptions.outputPath),
4550
projectName: context.projectName,
4651
projectRoot: normalizedOptions.projectRoot,
47-
rootDir: normalizedOptions.rootDir,
48-
tsConfig: normalizedOptions.tsConfig,
52+
rootDir: joinPathFragments(normalizedOptions.rootDir),
53+
tsConfig: joinPathFragments(normalizedOptions.tsConfig),
4954
watch: normalizedOptions.watch,
5055
deleteOutputPath: normalizedOptions.clean,
5156
getCustomTransformers: getCustomTrasformersFactory(

packages/js/src/generators/library/library.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ async function addProject(tree: Tree, options: NormalizedSchema) {
251251
}
252252

253253
if (options.publishable) {
254-
const packageRoot = join(defaultOutputDirectory, '{projectRoot}');
254+
const packageRoot = joinPathFragments(
255+
defaultOutputDirectory,
256+
'{projectRoot}'
257+
);
255258

256259
projectConfiguration.targets ??= {};
257260
projectConfiguration.targets['nx-release-publish'] = {

packages/js/src/generators/release-version/release-version.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Valid values are: ${validReleaseVersionPrefixes
140140
);
141141
}
142142

143-
const packageJsonPath = join(packageRoot, 'package.json');
143+
const packageJsonPath = joinPathFragments(packageRoot, 'package.json');
144144
if (!tree.exists(packageJsonPath)) {
145145
throw new Error(
146146
`The project "${projectName}" does not have a package.json available at ${packageJsonPath}.
@@ -830,7 +830,7 @@ To fix this you will either need to add a package.json file at that location, or
830830
`The project "${dependencyProjectName}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`
831831
);
832832
}
833-
const dependencyPackageJsonPath = join(
833+
const dependencyPackageJsonPath = joinPathFragments(
834834
dependencyPackageRoot,
835835
'package.json'
836836
);

packages/js/src/generators/release-version/utils/resolve-version-spec.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { join } from 'path';
21
import { resolveVersionSpec } from './resolve-version-spec';
32

43
describe('resolveVersionSpec()', () => {
@@ -67,7 +66,7 @@ describe('resolveVersionSpec()', () => {
6766
'file:../projectB',
6867
'/packages/projectB'
6968
)
70-
).toEqual(expect.stringContaining(join('/packages/projectB')));
69+
).toEqual(expect.stringContaining('/packages/projectB'));
7170
});
7271

7372
it('should work for a yarn classic style link reference', async () => {
@@ -78,6 +77,6 @@ describe('resolveVersionSpec()', () => {
7877
'link:../projectB',
7978
'/packages/projectB'
8079
)
81-
).toEqual(expect.stringContaining(join('/packages/projectB')));
80+
).toEqual(expect.stringContaining('/packages/projectB'));
8281
});
8382
});

0 commit comments

Comments
 (0)