-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(generators): fix and refactor entry util, add tests (#1392)
Co-authored-by: James George <[email protected]>
- Loading branch information
1 parent
e993ff3
commit 219c633
Showing
3 changed files
with
119 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
jest.setMock('@webpack-cli/webpack-scaffold', { | ||
Input: jest.fn(), | ||
InputValidate: jest.fn(), | ||
}); | ||
|
||
import { Input, InputValidate } from '@webpack-cli/webpack-scaffold'; | ||
import entry from '../../lib/utils/entry'; | ||
|
||
describe('entry', () => { | ||
const InputMock = Input as jest.Mock; | ||
const InputValidateMock = InputValidate as jest.Mock; | ||
|
||
it('handles single entry empty string', async () => { | ||
InputMock.mockReturnValue({ | ||
singularEntry: '', | ||
}); | ||
expect(await entry(null, false, null)).toEqual(''); | ||
}); | ||
|
||
it('handles single entry path', async () => { | ||
InputMock.mockReturnValue({ | ||
singularEntry: 'path/to/index', | ||
}); | ||
expect(await entry(null, false, null)).toEqual('\'./path/to/index.js\''); | ||
}); | ||
|
||
it('handles single entry path with js extension', async () => { | ||
InputMock.mockReturnValue({ | ||
singularEntry: 'path/to/index.js', | ||
}); | ||
expect(await entry(null, false, null)).toEqual('\'./path/to/index.js\''); | ||
}); | ||
|
||
it('handles single entry relative path', async () => { | ||
InputMock.mockReturnValue({ | ||
singularEntry: './path/to/index', | ||
}); | ||
expect(await entry(null, false, null)).toEqual('\'./path/to/index.js\''); | ||
}); | ||
|
||
it('handles multiple entry paths', async () => { | ||
let calls = 0; | ||
InputValidateMock.mockImplementation(() => { | ||
calls++; | ||
if (calls === 1) { | ||
return { | ||
multipleEntries: 'test1, test2', | ||
}; | ||
} else if (calls === 2) { | ||
return { | ||
test1: 'src/test1', | ||
}; | ||
} else { | ||
return { | ||
test2: 'src/test2', | ||
}; | ||
} | ||
}); | ||
expect(await entry(null, true, null)).toEqual({ | ||
test1: '\'./src/test1.js\'', | ||
test2: '\'./src/test2.js\'', | ||
}); | ||
}); | ||
|
||
it('handles multiple entry paths with varying formats', async () => { | ||
let calls = 0; | ||
InputValidateMock.mockImplementation(() => { | ||
calls++; | ||
if (calls === 1) { | ||
return { | ||
multipleEntries: ' test1 , test2 ', | ||
}; | ||
} else if (calls === 2) { | ||
return { | ||
test1: './path/to/test1', | ||
}; | ||
} else { | ||
return { | ||
test2: 'src/test2.js', | ||
}; | ||
} | ||
}); | ||
expect(await entry(null, true, null)).toEqual({ | ||
test1: '\'./path/to/test1.js\'', | ||
test2: '\'./src/test2.js\'', | ||
}); | ||
}); | ||
}); |
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