Skip to content

Commit b3c2d15

Browse files
committed
add a test
1 parent b2f6c73 commit b3c2d15

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

test/fixtures/javascript.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./secret_js.txt')

test/fixtures/raw_js_mod.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = function (src) {
2+
this._module._jsSource = true
3+
return src
4+
}

test/fixtures/secret_js.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ look: 'this is actually valid js!' }

test/index.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test.cb('basic text content works correctly', (t) => {
1414
resolveLoader: {
1515
alias: { source: path.join(__dirname, '../lib/index.js') }
1616
},
17-
module: { loaders: [{ test: /\.txt$/, loader: 'source' }] }
17+
module: { rules: [{ test: /\.txt$/, loader: 'source' }] }
1818
}, (err, res) => {
1919
if (err) { t.fail(err) }
2020
t.truthy(res.compilation.errors.length < 1)
@@ -33,7 +33,7 @@ test.cb('raw source is added to loader context', (t) => {
3333
resolveLoader: {
3434
alias: { source: path.join(__dirname, '../lib/index.js') }
3535
},
36-
module: { loaders: [{ test: /\.txt$/, loader: 'source' }] }
36+
module: { rules: [{ test: /\.txt$/, loader: 'source' }] }
3737
}, (err, res) => {
3838
if (err) { t.fail(err) }
3939
const mod = res.compilation.modules.find((m) => {
@@ -55,7 +55,7 @@ test.cb('binary files not exported but are made availble for plugins', (t) => {
5555
resolveLoader: {
5656
alias: { source: path.join(__dirname, '../lib/index.js') }
5757
},
58-
module: { loaders: [{ test: /\.gif$/, loader: 'source' }] }
58+
module: { rules: [{ test: /\.gif$/, loader: 'source' }] }
5959
}, (err, res) => {
6060
if (err) { t.fail(err) }
6161
const src = fs.readFileSync(outputPath, 'utf8')
@@ -64,3 +64,31 @@ test.cb('binary files not exported but are made availble for plugins', (t) => {
6464
t.end()
6565
})
6666
})
67+
68+
test.cb('valid js source parsed by setting the _jsSource prop', (t) => {
69+
const outputPath = path.join(fixturesPath, 'build-js.js')
70+
webpack({
71+
context: fixturesPath,
72+
entry: path.join(fixturesPath, 'javascript'),
73+
output: { path: fixturesPath, filename: 'build-js.js' },
74+
resolveLoader: {
75+
alias: {
76+
source: path.join(__dirname, '../lib/index.js'),
77+
rawJs: path.join(__dirname, './fixtures/raw_js_mod.js')
78+
}
79+
},
80+
module: {
81+
rules: [{
82+
test: /\.txt$/,
83+
use: [{ loader: 'source' }, { loader: 'rawJs' }]
84+
}]
85+
}
86+
}, (err, res) => {
87+
if (err) { t.fail(err) }
88+
t.truthy(res.compilation.errors.length < 1)
89+
const src = fs.readFileSync(outputPath, 'utf8')
90+
t.regex(src, /module\.exports = { look: 'this is actually valid js!' }/)
91+
fs.unlinkSync(outputPath)
92+
t.end()
93+
})
94+
})

yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,8 @@ concordance@^3.0.0:
10751075
well-known-symbols "^1.0.0"
10761076

10771077
configstore@^3.0.0:
1078-
version "3.1.0"
1079-
resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.0.tgz#45df907073e26dfa1cf4b2d52f5b60545eaa11d1"
1078+
version "3.1.1"
1079+
resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.1.tgz#094ee662ab83fad9917678de114faaea8fcdca90"
10801080
dependencies:
10811081
dot-prop "^4.1.0"
10821082
graceful-fs "^4.1.2"
@@ -2479,7 +2479,7 @@ istanbul-lib-hook@^1.0.7:
24792479
dependencies:
24802480
append-transform "^0.4.0"
24812481

2482-
istanbul-lib-instrument@^1.7.3:
2482+
istanbul-lib-instrument@^1.7.4:
24832483
version "1.7.4"
24842484
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.7.4.tgz#e9fd920e4767f3d19edc765e2d6b3f5ccbd0eea8"
24852485
dependencies:
@@ -2998,8 +2998,8 @@ number-is-nan@^1.0.0:
29982998
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
29992999

30003000
nyc@^11.0.3:
3001-
version "11.0.3"
3002-
resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.0.3.tgz#0c28bc669a851621709bf7a08503034bee3812b6"
3001+
version "11.1.0"
3002+
resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.1.0.tgz#d6b3c5e16892a25af63138ba484676aa8a22eda7"
30033003
dependencies:
30043004
archy "^1.0.0"
30053005
arrify "^1.0.1"
@@ -3013,7 +3013,7 @@ nyc@^11.0.3:
30133013
glob "^7.0.6"
30143014
istanbul-lib-coverage "^1.1.1"
30153015
istanbul-lib-hook "^1.0.7"
3016-
istanbul-lib-instrument "^1.7.3"
3016+
istanbul-lib-instrument "^1.7.4"
30173017
istanbul-lib-report "^1.1.1"
30183018
istanbul-lib-source-maps "^1.2.1"
30193019
istanbul-reports "^1.1.1"
@@ -3024,7 +3024,7 @@ nyc@^11.0.3:
30243024
resolve-from "^2.0.0"
30253025
rimraf "^2.5.4"
30263026
signal-exit "^3.0.1"
3027-
spawn-wrap "^1.3.7"
3027+
spawn-wrap "^1.3.8"
30283028
test-exclude "^4.1.1"
30293029
yargs "^8.0.1"
30303030
yargs-parser "^5.0.0"
@@ -3832,7 +3832,7 @@ source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, sour
38323832
version "0.5.6"
38333833
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
38343834

3835-
spawn-wrap@^1.3.7:
3835+
spawn-wrap@^1.3.8:
38363836
version "1.3.8"
38373837
resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.3.8.tgz#fa2a79b990cbb0bb0018dca6748d88367b19ec31"
38383838
dependencies:

0 commit comments

Comments
 (0)