mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 13:51:27 +08:00
129 lines
3.0 KiB
TypeScript
129 lines
3.0 KiB
TypeScript
import Config from 'webpack-chain';
|
|
|
|
import {
|
|
mockExistsSync,
|
|
restoreExistsSync,
|
|
addMockFile,
|
|
fsExistsSyncSpy,
|
|
} from '../../scripts/jest.utils';
|
|
|
|
import { applyFileReplacements } from '../../src/helpers/fileReplacements';
|
|
import { additionalCopyRules } from '../../src/helpers/copyRules';
|
|
import base from '../../src/configuration/base';
|
|
import { init } from '../../src';
|
|
|
|
describe('base configuration', () => {
|
|
const platforms = ['ios', 'android'];
|
|
|
|
beforeAll(() => {
|
|
mockExistsSync();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
fsExistsSyncSpy.mockClear();
|
|
});
|
|
|
|
afterAll(() => {
|
|
restoreExistsSync();
|
|
});
|
|
|
|
for (let platform of platforms) {
|
|
it(`for ${platform}`, () => {
|
|
init({
|
|
[platform]: true,
|
|
|
|
// only test in base config to make sure App_Resources
|
|
// are properly excluded from the copy-rules
|
|
appResourcesPath: 'custom_app_resources',
|
|
});
|
|
expect(base(new Config()).toString()).toMatchSnapshot();
|
|
});
|
|
}
|
|
|
|
it('support env.watchNodeModules', () => {
|
|
init({
|
|
ios: true,
|
|
watchNodeModules: true,
|
|
});
|
|
expect(base(new Config()).get('snapshot')).toMatchSnapshot();
|
|
});
|
|
|
|
it('supports dotenv', () => {
|
|
const cleanupMockFile = addMockFile('__jest__/.env');
|
|
|
|
init({
|
|
ios: true,
|
|
});
|
|
const config = base(new Config());
|
|
|
|
expect(config.plugin('DotEnvPlugin')).toBeDefined();
|
|
config.plugin('DotEnvPlugin').tap((args) => {
|
|
expect(args[0].path).toEqual('__jest__/.env');
|
|
return args;
|
|
});
|
|
|
|
cleanupMockFile();
|
|
});
|
|
|
|
it('supports env specific dotenv', () => {
|
|
const cleanupMockFile = addMockFile('__jest__/.env.prod');
|
|
|
|
init({
|
|
ios: true,
|
|
env: 'prod',
|
|
});
|
|
const config = base(new Config());
|
|
|
|
expect(fsExistsSyncSpy).toHaveBeenCalledWith('__jest__/.env.prod');
|
|
expect(config.plugin('DotEnvPlugin')).toBeDefined();
|
|
config.plugin('DotEnvPlugin').tap((args) => {
|
|
expect(args[0].path).toEqual('__jest__/.env.prod');
|
|
return args;
|
|
});
|
|
|
|
cleanupMockFile();
|
|
});
|
|
|
|
it('falls back to default .env', () => {
|
|
const cleanupMockFile = addMockFile('__jest__/.env');
|
|
|
|
init({
|
|
ios: true,
|
|
env: 'prod',
|
|
});
|
|
const config = base(new Config());
|
|
|
|
expect(fsExistsSyncSpy).toHaveBeenCalledWith('__jest__/.env.prod');
|
|
expect(fsExistsSyncSpy).toHaveBeenCalledWith('__jest__/.env');
|
|
|
|
expect(config.plugin('DotEnvPlugin')).toBeDefined();
|
|
config.plugin('DotEnvPlugin').tap((args) => {
|
|
expect(args[0].path).toEqual('__jest__/.env');
|
|
return args;
|
|
});
|
|
|
|
cleanupMockFile();
|
|
});
|
|
|
|
it('applies file replacements', () => {
|
|
const config = new Config();
|
|
applyFileReplacements(config, {
|
|
// should apply as an alias
|
|
'foo.ts': 'foo.replaced.ts',
|
|
'bar.js': 'bar.replaced.js',
|
|
|
|
// should apply as a file replacement using the copy plugin
|
|
'foo.json': 'foo.replaced.json',
|
|
});
|
|
|
|
expect(config.resolve.alias.get('foo.ts')).toBe('foo.replaced.ts');
|
|
expect(config.resolve.alias.get('bar.js')).toBe('bar.replaced.js');
|
|
expect(additionalCopyRules.length).toBe(1);
|
|
expect(additionalCopyRules[0]).toEqual({
|
|
from: 'foo.replaced.json',
|
|
to: 'foo.json',
|
|
force: true,
|
|
});
|
|
});
|
|
});
|