-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(build-env): rename utils functions add test
- Loading branch information
Showing
10 changed files
with
61 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 1 addition & 6 deletions
7
...ing/build-env/src/internal/utils/utils.ts → ...ng/build-env/src/internal/utils/target.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
import { mkdir } from 'node:fs/promises'; | ||
import type { TargetConfiguration } from '@nx/devkit'; | ||
|
||
export function getBuildOutput(target?: TargetConfiguration) { | ||
export function getTargetOutputPath(target?: TargetConfiguration) { | ||
const { options } = target ?? {}; | ||
const { outputPath } = options ?? {}; | ||
if (!outputPath) { | ||
throw new Error('outputPath is required'); | ||
} | ||
return outputPath; | ||
} | ||
|
||
export function uniquePort(): number { | ||
return Number((6000 + Number(Math.random() * 1000)).toFixed(0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { getTargetOutputPath } from './target'; | ||
|
||
describe('getTargetOutputPath', () => { | ||
it('should return output path of the build target if given', () => { | ||
expect( | ||
getTargetOutputPath({ | ||
options: { | ||
outputPath: 'out-dir', | ||
}, | ||
}) | ||
).toBe('out-dir'); | ||
}); | ||
|
||
it('should throw if no outputPath is given in options', () => { | ||
expect( | ||
getTargetOutputPath({ | ||
options: {}, | ||
}) | ||
).toThrow('outputPath is required'); | ||
}); | ||
|
||
it('should throw if empty onject is passed', () => { | ||
expect(getTargetOutputPath({})).toThrow('outputPath is required'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function uniquePort(): number { | ||
return Number((6000 + Number(Math.random() * 1000)).toFixed(0)); | ||
} |
12 changes: 12 additions & 0 deletions
12
tooling/build-env/src/internal/utils/unique-port.unit-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { uniquePort } from './unique-port'; | ||
|
||
describe('uniquePort', () => { | ||
it('should return a different number on every call', () => { | ||
const portsArray = new Array(100).fill(0).map(() => uniquePort()); | ||
expect(portsArray.length).toBe(new Set(portsArray).size); | ||
}); | ||
|
||
it('should return random number bigger then 6000', () => { | ||
expect(uniquePort()).toBeGreaterThan(6000); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const VERDACCIO_REGISTRY_JSON = 'verdaccio-registry.json'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters