Skip to content

Commit

Permalink
Add execution-test for option "contextAsConfigBasePath".
Browse files Browse the repository at this point in the history
  • Loading branch information
christiantinauer committed Nov 17, 2017
1 parent ebd2bb5 commit 4c713e0
Show file tree
Hide file tree
Showing 10 changed files with 1,130 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -110,7 +110,7 @@ function getLoaderOptions(loader: Webpack) {
}

type ValidLoaderOptions = keyof LoaderOptions;
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs' /* DEPRECATED */, 'onlyCompileBundledFiles', 'happyPackMode', 'getCustomTransformers'];
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'contextAsConfigBasePath', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs' /* DEPRECATED */, 'onlyCompileBundledFiles', 'happyPackMode', 'getCustomTransformers'];

/**
* Validate the supplied loader options.
Expand Down
45 changes: 45 additions & 0 deletions test/execution-tests/option-contextAsConfigBasePath/karma.conf.js
@@ -0,0 +1,45 @@
/* eslint-disable no-var, strict */
'use strict';
var webpackConfig = require('./webpack.config.js');
var reporterOptions = require('../../reporterOptions');

module.exports = function(config) {
// Documentation: https://karma-runner.github.io/0.13/config/configuration-file.html
config.set({
browsers: [ 'ChromeHeadless' ],

files: [
// This ensures we have the es6 shims in place and then loads all the tests
'main.js'
],

port: 9876,

frameworks: [ 'jasmine' ],

logLevel: config.LOG_INFO, //config.LOG_DEBUG

preprocessors: {
'main.js': [ 'webpack', 'sourcemap' ]
},

webpack: {
devtool: 'inline-source-map',
module: webpackConfig.module,
resolve: webpackConfig.resolve,

// for test harness purposes only, you would not need this in a normal project
resolveLoader: webpackConfig.resolveLoader
},

webpackMiddleware: {
quiet: true,
stats: {
colors: true
}
},

// reporter options
mochaReporter: reporterOptions
});
};
4 changes: 4 additions & 0 deletions test/execution-tests/option-contextAsConfigBasePath/main.js
@@ -0,0 +1,4 @@
import 'babel-polyfill';

const testsContext = require.context('./', true, /\.tests\.ts(x?)$/);
testsContext.keys().forEach(testsContext);
26 changes: 26 additions & 0 deletions test/execution-tests/option-contextAsConfigBasePath/package.json
@@ -0,0 +1,26 @@
{
"name": "es6-babel-react",
"license": "MIT",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {
"@types/jasmine": "^2.5.35",
"@types/react": "^0.14.41",
"@types/react-addons-test-utils": "^0.14.15",
"@types/react-test-renderer": "^15.5.0",
"@types/react-dom": "^0.14.18",
"babel": "^6.0.0",
"babel-core": "^6.0.0",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-react": "^6.0.0",
"jasmine-core": "^2.3.4",
"react-addons-test-utils": "^15.3.1",
"react-test-renderer": "^15.5.4"
},
"dependencies": {
"babel-polyfill": "^6.0.0",
"react": "^15.4.1",
"react-dom": "^15.4.1"
}
}
@@ -0,0 +1,8 @@
import React from 'react';

const App: React.SFC<{ name: string }> = ({ name }) =>
<div className="container-fluid">
<h1>Hello {name}!</h1>
</div>;

export default App;
@@ -0,0 +1,7 @@
import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';

import App from './components/App';

ReactDOM.render(<App name="James" />, document.getElementById('content'));
@@ -0,0 +1,21 @@
import React from 'react';
import { createRenderer } from 'react-test-renderer/shallow';

import App from '../../src/components/App';

describe('App', () => {
it('simple', () => expect(1).toBe(1));

it('renders expected HTML', () => {
const shallowRenderer = createRenderer();

shallowRenderer.render(<App name="James" />);
const app = shallowRenderer.getRenderOutput();

expect(app).toEqual(
<div className="container-fluid">
<h1>Hello { "James" }!</h1>
</div>
);
});
});
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"lib": [
"dom",
"es2015"
],
"jsx": "preserve",
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"skipLibCheck": true
}
}
@@ -0,0 +1,60 @@
/* eslint-disable no-var, strict, prefer-arrow-callback */
'use strict';

var path = require('path');
var webpack = require('webpack');

var babelOptions = {
"presets": [
"react",
[
"es2015",
{
"modules": false
}
],
"es2016"
]
};

module.exports = {
entry: './src/main.tsx',
output: {
filename: 'bundle.js'
},
module: {
rules: [{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: babelOptions
},
{
loader: 'ts-loader',
options: {
contextAsConfigBasePath: true,
configFile: require.resolve('./tsconfig-container/tsconfig.json')
}
}
]
}, {
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: babelOptions
}
]
}]
},
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ['.ts', '.tsx', '.js']
},
};

// for test harness purposes only, you would not need this in a normal project
module.exports.resolveLoader = { alias: { 'ts-loader': path.join(__dirname, "../../../index.js") } }

0 comments on commit 4c713e0

Please sign in to comment.