Skip to content

Commit 8ae5322

Browse files
author
John Doe
committed
refactor: improve tests
1 parent da0e18e commit 8ae5322

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,32 @@ import {
1010
} from './test-folder-setup.js';
1111

1212
describe('restoreNxIgnoredFiles', () => {
13+
it('should rename Nx ignored files target folder and keep the rest unchanged', async () => {
14+
vol.fromJSON(
15+
{
16+
'/_nx.json': '',
17+
'/_package.json': '',
18+
'/_project.json': '',
19+
'/projects/lib1/_package.json': '',
20+
'/projects/lib1/_project.json': '',
21+
'/projects/lib2/_package.json': '',
22+
'/projects/lib2/_project.json': '',
23+
},
24+
MEMFS_VOLUME,
25+
);
26+
27+
await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow();
28+
29+
expect(vol.toJSON()).toStrictEqual({
30+
'/nx.json': '',
31+
'/package.json': '',
32+
'/project.json': '',
33+
'/projects/lib1/package.json': '',
34+
'/projects/lib1/project.json': '',
35+
'/projects/lib2/package.json': '',
36+
'/projects/lib2/project.json': '',
37+
});
38+
});
1339
it('should rename Nx ignored files in a folder', async () => {
1440
vol.fromJSON(
1541
{
@@ -22,12 +48,11 @@ describe('restoreNxIgnoredFiles', () => {
2248

2349
await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow();
2450

25-
expect(vol.existsSync('/nx.json')).toBe(true);
26-
expect(vol.existsSync('/_nx.json')).toBe(false);
27-
expect(vol.existsSync('/package.json')).toBe(true);
28-
expect(vol.existsSync('/_package.json')).toBe(false);
29-
expect(vol.existsSync('/project.json')).toBe(true);
30-
expect(vol.existsSync('/_project.json')).toBe(false);
51+
expect(vol.toJSON()).toStrictEqual({
52+
'/nx.json': '',
53+
'/package.json': '',
54+
'/project.json': '',
55+
});
3156
});
3257

3358
it('should throw if target folder does not exist', async () => {
@@ -41,25 +66,20 @@ describe('restoreNxIgnoredFiles', () => {
4166
it('should rename Nx ignored files in nested folders', async () => {
4267
vol.fromJSON(
4368
{
44-
'/workspaces/workspace1/_nx.json': '{}',
45-
'/workspaces/workspace1/_package.json': '{}',
46-
'/workspaces/workspace1/lib1/_project.json': '{}',
69+
'/workspaces/workspace1/_nx.json': '',
70+
'/workspaces/workspace1/_package.json': '',
71+
'/workspaces/workspace1/lib1/_project.json': '',
4772
},
4873
MEMFS_VOLUME,
4974
);
5075

5176
await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow();
5277

53-
expect(vol.existsSync('/workspaces/workspace1/nx.json')).toBe(true);
54-
expect(vol.existsSync('/workspaces/workspace1/_nx.json')).toBe(false);
55-
expect(vol.existsSync('/workspaces/workspace1/package.json')).toBe(true);
56-
expect(vol.existsSync('/workspaces/workspace1/_package.json')).toBe(false);
57-
expect(vol.existsSync('/workspaces/workspace1/lib1/project.json')).toBe(
58-
true,
59-
);
60-
expect(vol.existsSync('/workspaces/workspace1/lib1/_project.json')).toBe(
61-
false,
62-
);
78+
expect(vol.toJSON()).toStrictEqual({
79+
'/workspaces/workspace1/nx.json': '',
80+
'/workspaces/workspace1/package.json': '',
81+
'/workspaces/workspace1/lib1/project.json': '',
82+
});
6383
});
6484
});
6585

0 commit comments

Comments
 (0)