Skip to content

Commit 4b36306

Browse files
authored
add execution test for resolveJsonModule (#854)
* add execution test for resolveJsonModule * minimum supported ts-loader version for resolveJsonModule 3.0.1
1 parent 5490e9d commit 4b36306

File tree

9 files changed

+124
-0
lines changed

9 files changed

+124
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable no-var, strict */
2+
'use strict';
3+
var path = require('path');
4+
var webpack = require('webpack');
5+
var webpackConfig = require('./webpack.config.js');
6+
var reporterOptions = require('../../reporterOptions');
7+
8+
module.exports = function(config) {
9+
config.set({
10+
browsers: [ 'ChromeHeadless' ],
11+
12+
files: [
13+
// This loads all the tests
14+
'main.js'
15+
],
16+
17+
port: 9876,
18+
19+
frameworks: [ 'jasmine' ],
20+
21+
logLevel: config.LOG_INFO, //config.LOG_DEBUG
22+
23+
preprocessors: {
24+
'main.js': [ 'webpack', 'sourcemap' ]
25+
},
26+
27+
webpack: {
28+
devtool: 'inline-source-map',
29+
mode: webpackConfig.mode,
30+
module: webpackConfig.module,
31+
resolve: webpackConfig.resolve,
32+
33+
// for test harness purposes only, you would not need this in a normal project
34+
resolveLoader: webpackConfig.resolveLoader
35+
},
36+
37+
webpackMiddleware: {
38+
quiet: true,
39+
stats: {
40+
colors: true
41+
}
42+
},
43+
44+
// reporter options
45+
mochaReporter: reporterOptions
46+
});
47+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const testsContext = require.context('./', true, /\.tests\.ts(x?)$/);
2+
testsContext.keys().forEach(testsContext);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "basic",
3+
"license": "MIT",
4+
"version": "1.0.0",
5+
"main": "index.js",
6+
"devDependencies": {
7+
"@types/jasmine": "^2.5.35",
8+
"jasmine-core": "^2.3.4"
9+
}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as someJson from './some.json';
2+
3+
export function getString() {
4+
return someJson.looks;
5+
}
6+
export function getNumber() {
7+
return someJson.json;
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"looks": "like",
3+
"json": 5
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as app from '../src/app';
2+
3+
// We don't actually care about the result of the following operations;
4+
// what we care about is typescript resolving json as modules
5+
// allowing this code to compile without errors, hence this:
6+
// "noEmitOnError": true
7+
// in tsconfig.json
8+
describe("app", () => {
9+
it("getString returns the expected value", () => {
10+
expect(app.getString()).toBe("like");
11+
});
12+
13+
it("getNumber returns the expected value", () => {
14+
expect(app.getNumber()).toBe(5);
15+
});
16+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"noEmitOnError": true,
4+
"resolveJsonModule": true
5+
}
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var path = require('path')
2+
3+
module.exports = {
4+
mode: 'development',
5+
entry: './app.ts',
6+
output: {
7+
filename: 'bundle.js'
8+
},
9+
resolve: {
10+
extensions: ['.ts', '.js']
11+
},
12+
module: {
13+
rules: [
14+
{ test: /\.ts$/, loader: 'ts-loader' }
15+
]
16+
}
17+
}
18+
19+
// for test harness purposes only, you would not need this in a normal project
20+
module.exports.resolveLoader = { alias: { 'ts-loader': path.join(__dirname, "../../../index.js") } }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@types/jasmine@^2.5.35":
6+
version "2.8.5"
7+
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.5.tgz#96e58872583fa80c7ea0dd29024b180d5e133678"
8+
9+
jasmine-core@^2.3.4:
10+
version "2.9.1"
11+
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.9.1.tgz#b6bbc1d8e65250d56f5888461705ebeeeb88f22f"

0 commit comments

Comments
 (0)