Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Jul 21, 2017
1 parent b2f6c73 commit b3c2d15
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
1 change: 1 addition & 0 deletions test/fixtures/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./secret_js.txt')
4 changes: 4 additions & 0 deletions test/fixtures/raw_js_mod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function (src) {
this._module._jsSource = true
return src
}
1 change: 1 addition & 0 deletions test/fixtures/secret_js.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ look: 'this is actually valid js!' }
34 changes: 31 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.cb('basic text content works correctly', (t) => {
resolveLoader: {
alias: { source: path.join(__dirname, '../lib/index.js') }
},
module: { loaders: [{ test: /\.txt$/, loader: 'source' }] }
module: { rules: [{ test: /\.txt$/, loader: 'source' }] }
}, (err, res) => {
if (err) { t.fail(err) }
t.truthy(res.compilation.errors.length < 1)
Expand All @@ -33,7 +33,7 @@ test.cb('raw source is added to loader context', (t) => {
resolveLoader: {
alias: { source: path.join(__dirname, '../lib/index.js') }
},
module: { loaders: [{ test: /\.txt$/, loader: 'source' }] }
module: { rules: [{ test: /\.txt$/, loader: 'source' }] }
}, (err, res) => {
if (err) { t.fail(err) }
const mod = res.compilation.modules.find((m) => {
Expand All @@ -55,7 +55,7 @@ test.cb('binary files not exported but are made availble for plugins', (t) => {
resolveLoader: {
alias: { source: path.join(__dirname, '../lib/index.js') }
},
module: { loaders: [{ test: /\.gif$/, loader: 'source' }] }
module: { rules: [{ test: /\.gif$/, loader: 'source' }] }
}, (err, res) => {
if (err) { t.fail(err) }
const src = fs.readFileSync(outputPath, 'utf8')
Expand All @@ -64,3 +64,31 @@ test.cb('binary files not exported but are made availble for plugins', (t) => {
t.end()
})
})

test.cb('valid js source parsed by setting the _jsSource prop', (t) => {
const outputPath = path.join(fixturesPath, 'build-js.js')
webpack({
context: fixturesPath,
entry: path.join(fixturesPath, 'javascript'),
output: { path: fixturesPath, filename: 'build-js.js' },
resolveLoader: {
alias: {
source: path.join(__dirname, '../lib/index.js'),
rawJs: path.join(__dirname, './fixtures/raw_js_mod.js')
}
},
module: {
rules: [{
test: /\.txt$/,
use: [{ loader: 'source' }, { loader: 'rawJs' }]
}]
}
}, (err, res) => {
if (err) { t.fail(err) }
t.truthy(res.compilation.errors.length < 1)
const src = fs.readFileSync(outputPath, 'utf8')
t.regex(src, /module\.exports = { look: 'this is actually valid js!' }/)
fs.unlinkSync(outputPath)
t.end()
})
})
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,8 @@ concordance@^3.0.0:
well-known-symbols "^1.0.0"

configstore@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.0.tgz#45df907073e26dfa1cf4b2d52f5b60545eaa11d1"
version "3.1.1"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.1.tgz#094ee662ab83fad9917678de114faaea8fcdca90"
dependencies:
dot-prop "^4.1.0"
graceful-fs "^4.1.2"
Expand Down Expand Up @@ -2479,7 +2479,7 @@ istanbul-lib-hook@^1.0.7:
dependencies:
append-transform "^0.4.0"

istanbul-lib-instrument@^1.7.3:
istanbul-lib-instrument@^1.7.4:
version "1.7.4"
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.7.4.tgz#e9fd920e4767f3d19edc765e2d6b3f5ccbd0eea8"
dependencies:
Expand Down Expand Up @@ -2998,8 +2998,8 @@ number-is-nan@^1.0.0:
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"

nyc@^11.0.3:
version "11.0.3"
resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.0.3.tgz#0c28bc669a851621709bf7a08503034bee3812b6"
version "11.1.0"
resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.1.0.tgz#d6b3c5e16892a25af63138ba484676aa8a22eda7"
dependencies:
archy "^1.0.0"
arrify "^1.0.1"
Expand All @@ -3013,7 +3013,7 @@ nyc@^11.0.3:
glob "^7.0.6"
istanbul-lib-coverage "^1.1.1"
istanbul-lib-hook "^1.0.7"
istanbul-lib-instrument "^1.7.3"
istanbul-lib-instrument "^1.7.4"
istanbul-lib-report "^1.1.1"
istanbul-lib-source-maps "^1.2.1"
istanbul-reports "^1.1.1"
Expand All @@ -3024,7 +3024,7 @@ nyc@^11.0.3:
resolve-from "^2.0.0"
rimraf "^2.5.4"
signal-exit "^3.0.1"
spawn-wrap "^1.3.7"
spawn-wrap "^1.3.8"
test-exclude "^4.1.1"
yargs "^8.0.1"
yargs-parser "^5.0.0"
Expand Down Expand Up @@ -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
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

spawn-wrap@^1.3.7:
spawn-wrap@^1.3.8:
version "1.3.8"
resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.3.8.tgz#fa2a79b990cbb0bb0018dca6748d88367b19ec31"
dependencies:
Expand Down

0 comments on commit b3c2d15

Please sign in to comment.