mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(webpack): read nativescript.config.ts main if set before fallback to package.json (#9769)
implements #9658 BREAKING CHANGES: Possibly breaking if a project has a main field set in the nativescript.config.ts - since after this lands, this value will be used instead of package.json main. The impact is likely very small, the steps to migrate: (Option A) remove main from nativescript.config.ts if set (Option B) update main to the correct path in nativescript.config.ts if set incorrectly
This commit is contained in:
49
packages/webpack5/__tests__/helpers/platform.spec.ts
Normal file
49
packages/webpack5/__tests__/helpers/platform.spec.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { env } from '../../src/';
|
||||
import { addPlatform, getEntryPath } from '../../src/helpers/platform';
|
||||
|
||||
import { getValue } from '../../src/helpers/config';
|
||||
|
||||
describe('getEntryPath', () => {
|
||||
it('uses platform getEntryPath if the platform specifies it', () => {
|
||||
env.platform = 'testPlatform';
|
||||
addPlatform('testPlatform', {
|
||||
getEntryPath() {
|
||||
return 'custom-entry-path';
|
||||
},
|
||||
});
|
||||
|
||||
const res = getEntryPath();
|
||||
expect(res).toEqual('custom-entry-path');
|
||||
|
||||
// cleanup env
|
||||
delete env.platform;
|
||||
});
|
||||
|
||||
it('uses main from nativescript.config.ts if set', () => {
|
||||
env.ios = true;
|
||||
|
||||
// mock getValue
|
||||
const getValueMock = getValue as jest.Mock;
|
||||
const getValueMockImpl = getValueMock.getMockImplementation();
|
||||
|
||||
getValueMock.mockImplementation((key) => {
|
||||
if (key === 'main') {
|
||||
return 'main-from-config';
|
||||
}
|
||||
});
|
||||
|
||||
const res = getEntryPath();
|
||||
expect(res).toEqual('__jest__/main-from-config');
|
||||
|
||||
// reset mock implementation
|
||||
getValueMock.mockImplementation(getValueMockImpl);
|
||||
});
|
||||
|
||||
it('uses main from package.json', () => {
|
||||
env.ios = true;
|
||||
|
||||
const res = getEntryPath();
|
||||
// set in jest.setup.ts mock for package.json...
|
||||
expect(res).toEqual('__jest__/src/app.js');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user