Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added speculative test of allowJsImportTypes scenario (should initially fail until fix is applied) #590

Merged
merged 8 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/servicesHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ function resolveModuleName(
isExternalLibraryImport: tsResolution.resolvedModule.isExternalLibraryImport
};
if (resolutionResult!) {
if (resolutionResult!.resolvedFileName === tsResolutionResult.resolvedFileName) {
if (resolutionResult!.resolvedFileName === tsResolutionResult.resolvedFileName ||
/node_modules(\\|\/).*\.d\.ts$/.test(tsResolutionResult.resolvedFileName)) {
resolutionResult!.isExternalLibraryImport = tsResolutionResult.isExternalLibraryImport;
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions test/execution-tests/2.1.4_babel-allowJsImportTypes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This test confirms that you can import typings from an npm module when `allowJs` is true. See details [#586](https://github.com/TypeStrong/ts-loader/issues/586).

This test is roughly based on https://github.com/bsouthga/ts-loader-types-error-example
51 changes: 51 additions & 0 deletions test/execution-tests/2.1.4_babel-allowJsImportTypes/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable no-var, strict */
'use strict';
var webpackConfig = require('./webpack.config.js');

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

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: {
colors: {
success: 'bgGreen',
info: 'cyan',
warning: 'bgBlue',
error: 'bgRed'
}
}
});
};
4 changes: 4 additions & 0 deletions test/execution-tests/2.1.4_babel-allowJsImportTypes/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'babel-polyfill';

const testsContext = require.context('./', true, /\.tests\.js$/);
testsContext.keys().forEach(testsContext);
16 changes: 16 additions & 0 deletions test/execution-tests/2.1.4_babel-allowJsImportTypes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "allow-js-import-types",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {
"babel": "^6.0.0",
"babel-core": "^6.0.0",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.0.0",
"jasmine-core": "^2.3.4"
},
"dependencies": {
"babel-polyfill": "^6.0.0",
"event-rank": "^0.0.10"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import EventRank from './imported';

export function getEventRank() {
return EventRank;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { EventRank } from 'event-rank';

export default EventRank;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var entry = require('../src/entry');

describe("entry", function() {
it("getEventRank produces something", function() {
var EventRank = entry.getEventRank();
expect(EventRank).not.toBeUndefined();
});
});
11 changes: 11 additions & 0 deletions test/execution-tests/2.1.4_babel-allowJsImportTypes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"allowJs": true,
"module": "es2015",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": false,
"sourceMap": true,
"target": "es2015"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable no-var, strict, prefer-arrow-callback */
'use strict';

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

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

module.exports = {
entry: './src/entry.js',
output: {
filename: 'bundle.js'
},
module: {
rules: [{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: babelOptions
},
{
loader: 'ts-loader',
options: { entryFileIsJs: true }
}
]
}, {
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") } }