feat: implement basic public api

This commit is contained in:
Igor Randjelovic
2020-11-18 14:10:44 +01:00
committed by Nathan Walker
parent ae12ee9324
commit cb7108d33c
18 changed files with 201 additions and 138 deletions

View File

@@ -17,7 +17,7 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
},
resolveLoader: {
modules: [
'@nativescript/webpack/loaders',
'@nativescript/webpack/dist/loaders',
'node_modules'
]
},
@@ -159,7 +159,7 @@ exports[`react configuration > android > base config 1`] = `
},
resolveLoader: {
modules: [
'@nativescript/webpack/loaders',
'@nativescript/webpack/dist/loaders',
'node_modules'
]
},
@@ -294,7 +294,7 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
},
resolveLoader: {
modules: [
'@nativescript/webpack/loaders',
'@nativescript/webpack/dist/loaders',
'node_modules'
]
},
@@ -439,7 +439,7 @@ exports[`react configuration > ios > base config 1`] = `
},
resolveLoader: {
modules: [
'@nativescript/webpack/loaders',
'@nativescript/webpack/dist/loaders',
'node_modules'
]
},

View File

@@ -17,7 +17,7 @@ exports[`vue configuration for android 1`] = `
},
resolveLoader: {
modules: [
'@nativescript/webpack/loaders',
'@nativescript/webpack/dist/loaders',
'node_modules'
]
},
@@ -155,7 +155,7 @@ exports[`vue configuration for ios 1`] = `
},
resolveLoader: {
modules: [
'@nativescript/webpack/loaders',
'@nativescript/webpack/dist/loaders',
'node_modules'
]
},

View File

@@ -1,10 +1,6 @@
import { __react } from '@nativescript/webpack';
// todo: maybe mock baseConfig as we test it separately?
// import Config from 'webpack-chain'
// jest.mock('../../src/configuration/base', () => () => {
// return new Config()
// })
// @ts-ignore
import Config from 'webpack-chain';
import react from '../../src/configuration/react';
describe('react configuration', () => {
const platforms = ['ios', 'android'];
@@ -13,7 +9,7 @@ describe('react configuration', () => {
describe(`> ${platform} >`, () => {
it(`base config`, () => {
expect(
__react({
react(new Config(), {
[platform]: true,
}).toString()
).toMatchSnapshot();
@@ -21,7 +17,7 @@ describe('react configuration', () => {
it(`adds ReactRefreshWebpackPlugin when HMR enabled`, () => {
expect(
__react({
react(new Config(), {
[platform]: true,
hmr: true,
}).toString()

View File

@@ -1,18 +1,14 @@
import { __vue } from '@nativescript/webpack';
// @ts-ignore
import Config from 'webpack-chain';
import vue from '../../src/configuration/vue';
// todo: maybe mock baseConfig as we test it separately?
// import Config from 'webpack-chain'
// jest.mock('../../src/configuration/base', () => () => {
// return new Config()
// })
describe('vue configuration', () => {
describe.only('vue configuration', () => {
const platforms = ['ios', 'android'];
for (let platform of platforms) {
it(`for ${platform}`, () => {
expect(
__vue({
vue(new Config(), {
[platform]: true,
}).toString()
).toMatchSnapshot();

View File

@@ -1,13 +1,32 @@
import * as webpack from '@nativescript/webpack';
// @ts-ignore
import Config from 'webpack-chain';
import * as webpack from '../src';
describe('@nativescript/webpack', () => {
it('exports base configs', () => {
expect(webpack.angularConfig).toBeInstanceOf(Function);
expect(webpack.baseConfig).toBeInstanceOf(Function);
expect(webpack.javascriptConfig).toBeInstanceOf(Function);
expect(webpack.reactConfig).toBeInstanceOf(Function);
expect(webpack.svelteConfig).toBeInstanceOf(Function);
expect(webpack.typescriptConfig).toBeInstanceOf(Function);
expect(webpack.vueConfig).toBeInstanceOf(Function);
it('exports the public api', () => {
expect(webpack.init).toBeInstanceOf(Function);
expect(webpack.useConfig).toBeInstanceOf(Function);
expect(webpack.chainWebpack).toBeInstanceOf(Function);
expect(webpack.mergeWebpack).toBeInstanceOf(Function);
expect(webpack.resolveChainableConfig).toBeInstanceOf(Function);
expect(webpack.resolveConfig).toBeInstanceOf(Function);
});
it('applies chain configs', () => {
expect(webpack.chainWebpack).toBeInstanceOf(Function);
const chainFn = jest.fn();
webpack.chainWebpack(chainFn);
// chainFn should not be called yet
expect(chainFn).not.toHaveBeenCalled();
// chainFn should only be called when
// resolving a chainable config
const config = webpack.resolveChainableConfig();
expect(chainFn).toHaveBeenCalledTimes(1);
expect(chainFn).toHaveBeenCalledWith(config, {});
expect(config).toBeInstanceOf(Config);
});
});