Skip to content

Commit

Permalink
fix(angular): fix path issues on windows for storybook generators and…
Browse files Browse the repository at this point in the history
… unit tests (#27489)

## Current Behavior
`nx test angular` fail on windows

## Expected Behavior
`nx test angular` to pass on windows

## notes
in
`packages/angular/src/generators/utils/storybook-ast/component-info.ts`
file I used `join(moduleFolderPath)` to convert it from always being `/`
to be OS separator
there are two other options I can do, but I don't have enough knowledge
to take the decision
1. to generate `moduleFolderPath` with OS separator instead of always
`/`
2. to make `candidateFile` to always be `/`

## Related Issue(s)
it might Fixes #22248
because now I see that when a new file is added, it's added to the end
of the tree, but when you reset it's then added to its place
also it explain why same code sometimes hit cache in windows, but miss
cache on linux, as the returned result different between the OSs
this should make sure that the returned result is always the same

---------

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
  • Loading branch information
robertIsaac and leosvelperez authored Feb 3, 2025
1 parent 05e0679 commit d655e66
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { UnitTestRunner } from '../../utils/test-runners';
import { componentGenerator } from '../component/component';
import { generateTestLibrary } from '../utils/testing';
import { componentTestGenerator } from './component-test';
import { EOL } from 'node:os';

jest.mock('@nx/cypress/src/utils/cypress-version');

Expand Down Expand Up @@ -226,7 +227,9 @@ describe(MyLibComponent.name, () => {
skipFormat: true,
});
expect(
tree.read('my-lib/src/lib/my-lib/my-lib.component.cy.ts', 'utf-8')
tree
.read('my-lib/src/lib/my-lib/my-lib.component.cy.ts', 'utf-8')
.replaceAll(EOL, '\n')
).toEqual(expected);

await componentTestGenerator(tree, {
Expand All @@ -237,7 +240,9 @@ describe(MyLibComponent.name, () => {
skipFormat: true,
});
expect(
tree.read('my-lib/src/lib/my-lib/my-lib.component.cy.ts', 'utf-8')
tree
.read('my-lib/src/lib/my-lib/my-lib.component.cy.ts', 'utf-8')
.replaceAll(EOL, '\n')
).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function getComponentInfoFromDir(

const componentImportPathChildren: string[] = [];
visitNotIgnoredFiles(tree, dir, (filePath) => {
componentImportPathChildren.push(filePath);
componentImportPathChildren.push(normalizePath(filePath));
});

for (const candidateFile of componentImportPathChildren) {
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/generators/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,11 @@ describe('tree', () => {
tree.write('parent/child/child-file2.txt', 'new child content');
tree.write('parent/new-child/new-child-file.txt', 'new child content');

expect(tree.children('parent')).toEqual([
expect(tree.children('parent').sort()).toEqual([
'child',
'new-child',
'parent-file-with-write-options.txt',
'parent-file.txt',
'new-child',
]);
expect(tree.children('parent/child')).toEqual([
'child-file.txt',
Expand Down

0 comments on commit d655e66

Please sign in to comment.