diff --git a/.editorconfig b/.editorconfig index 9f89f36..ab52458 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,5 +9,4 @@ insert_final_newline = true trim_trailing_whitespace = true [*.md] -insert_final_newline = true -trim_trailing_whitespace = false +trim_trailing_whitespace = false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f5ae7f2..8ac816a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [5.0.0](https://github.com/webpack-contrib/file-loader/compare/v4.2.0...v5.0.0) (2019-11-22) + + +### BREAKING CHANGES + +* minimum required nodejs version is `10.13.0` +* switch to ES modules by default (option `esModules` now is `true` by default) + + + ## [4.3.0](https://github.com/webpack-contrib/file-loader/compare/v4.2.0...v4.3.0) (2019-11-21) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6aa5912..34e1faa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -2,10 +2,13 @@ trigger: - master - next +variables: + npm_config_cache: $(Pipeline.Workspace)/.npm + jobs: - job: Lint pool: - vmImage: ubuntu-16.04 + vmImage: ubuntu-latest steps: - task: NodeTool@0 inputs: @@ -20,10 +23,12 @@ jobs: node -v npm -v displayName: 'Print versions' - - task: Npm@1 + - task: CacheBeta@1 inputs: - command: custom - customCommand: ci + key: npm | $(Agent.OS) | package-lock.json + path: $(npm_config_cache) + displayName: 'Cache npm' + - script: npm ci displayName: 'Install dependencies' - script: npm run lint displayName: 'Run lint' @@ -34,23 +39,22 @@ jobs: - job: Linux pool: - vmImage: ubuntu-16.04 + vmImage: ubuntu-latest strategy: maxParallel: 4 matrix: + node-13: + node_version: ^13.0.0 + webpack_version: latest node-12: node_version: ^12.0.0 webpack_version: latest node-10: node_version: ^10.13.0 webpack_version: latest - node-8: - node_version: ^8.9.0 - webpack_version: latest - node-8-canary: - node_version: ^8.9.0 + node-10-canary: + node_version: ^10.13.0 webpack_version: next - continue_on_error: true steps: - task: NodeTool@0 inputs: @@ -65,10 +69,12 @@ jobs: node -v npm -v displayName: 'Print versions' - - task: Npm@1 + - task: CacheBeta@1 inputs: - command: custom - customCommand: ci + key: npm | $(Agent.OS) | package-lock.json + path: $(npm_config_cache) + displayName: 'Cache npm' + - script: npm ci displayName: 'Install dependencies' - script: npm i webpack@$(webpack_version) displayName: 'Install "webpack@$(webpack_version)"' @@ -86,23 +92,22 @@ jobs: - job: macOS pool: - vmImage: macOS-10.14 + vmImage: macOS-latest strategy: maxParallel: 4 matrix: + node-13: + node_version: ^13.0.0 + webpack_version: latest node-12: node_version: ^12.0.0 webpack_version: latest node-10: node_version: ^10.13.0 webpack_version: latest - node-8: - node_version: ^8.9.0 - webpack_version: latest - node-8-canary: - node_version: ^8.9.0 + node-10-canary: + node_version: ^10.13.0 webpack_version: next - continue_on_error: true steps: - task: NodeTool@0 inputs: @@ -117,10 +122,12 @@ jobs: node -v npm -v displayName: 'Print versions' - - task: Npm@1 + - task: CacheBeta@1 inputs: - command: custom - customCommand: ci + key: npm | $(Agent.OS) | package-lock.json + path: $(npm_config_cache) + displayName: 'Cache npm' + - script: npm ci displayName: 'Install dependencies' - script: npm i webpack@$(webpack_version) displayName: 'Install "webpack@$(webpack_version)"' @@ -138,23 +145,22 @@ jobs: - job: Windows pool: - vmImage: windows-2019 + vmImage: windows-latest strategy: maxParallel: 4 matrix: + node-13: + node_version: ^13.0.0 + webpack_version: latest node-12: node_version: ^12.0.0 webpack_version: latest node-10: node_version: ^10.13.0 webpack_version: latest - node-8: - node_version: ^8.9.0 - webpack_version: latest - node-8-canary: - node_version: ^8.9.0 + node-10-canary: + node_version: ^10.13.0 webpack_version: next - continue_on_error: true steps: - script: 'git config --global core.autocrlf input' displayName: 'Config git core.autocrlf' @@ -172,10 +178,12 @@ jobs: node -v npm -v displayName: 'Print versions' - - task: Npm@1 + - task: CacheBeta@1 inputs: - command: custom - customCommand: ci + key: npm | $(Agent.OS) | package-lock.json + path: $(npm_config_cache) + displayName: 'Cache npm' + - script: npm ci displayName: 'Install dependencies' - script: npm i webpack@$(webpack_version) displayName: 'Install "webpack@$(webpack_version)"' diff --git a/babel.config.js b/babel.config.js index 4cf28ca..190c338 100644 --- a/babel.config.js +++ b/babel.config.js @@ -10,7 +10,7 @@ module.exports = (api) => { '@babel/preset-env', { targets: { - node: '8.9.0', + node: '10.13.0', }, }, ], diff --git a/lint-staged.config.js b/lint-staged.config.js index 77a86a7..618a5ec 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,4 +1,4 @@ module.exports = { '*.js': ['prettier --write', 'eslint --fix', 'git add'], - '*.{json,md,yml,css}': ['prettier --write', 'git add'], + '*.{json,md,yml,css,ts}': ['prettier --write', 'git add'], }; diff --git a/package-lock.json b/package-lock.json index 54ff891..731d3f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "file-loader", - "version": "4.3.0", + "version": "5.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1687,9 +1687,9 @@ } }, "@webpack-contrib/defaults": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/@webpack-contrib/defaults/-/defaults-5.1.1.tgz", - "integrity": "sha512-UvWJSpCBVzDpCASLhBuiSw/S5i57Z3FqO5X2cRqkvDR6TlhaPp0cXLr7R83xyRs2+eZ5pyl9UnP8HtSJx1s7Fw==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@webpack-contrib/defaults/-/defaults-6.0.2.tgz", + "integrity": "sha512-p0R2aEH3kSEnRCXoPAnymCZKE7FD9keXjK3LOk+1BnU4hdejz+8ahR2YuOGstC+1WEHoqF07xV82XD72LszkqQ==", "dev": true, "requires": { "chalk": "^2.3.0", @@ -3441,12 +3441,12 @@ "dev": true }, "core-js-compat": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.4.1.tgz", - "integrity": "sha512-YdeJI26gLc0CQJ9asLE5obEgBz2I0+CIgnoTbS2T0d5IPQw/OCgCIFR527RmpduxjrB3gSEHoGOCTq9sigOyfw==", + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.4.2.tgz", + "integrity": "sha512-W0Aj+LM3EAxxjD0Kp2o4be8UlnxIZHNupBv2znqrheR4aY2nOn91794k/xoSp+SxqqriiZpTsSwBtZr60cbkwQ==", "dev": true, "requires": { - "browserslist": "^4.7.2", + "browserslist": "^4.7.3", "semver": "^6.3.0" }, "dependencies": { @@ -4034,9 +4034,9 @@ } }, "electron-to-chromium": { - "version": "1.3.309", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.309.tgz", - "integrity": "sha512-NZd91XD15v2UPLjYXoN/gLnkwIUQjdH4SQLpRCCQiYJH6BBkfgp5pWemBJPr1rZ2dl8Ee3o91O9Sa1QuAfZmog==", + "version": "1.3.310", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.310.tgz", + "integrity": "sha512-ixvxy46JrDv5c8k1+th66Z+xDZD8zShNs6oh7hgyMpNZUgaoRBisXgFZKAyyhQTAj7oU2Y/uZ0AAsj/TY4N0tA==", "dev": true }, "elegant-spinner": { @@ -4679,6 +4679,12 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=" }, + "fast-extend": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/fast-extend/-/fast-extend-0.0.2.tgz", + "integrity": "sha1-9exCz0C5Rg9SGmOH37Ut7u1nHb0=", + "dev": true + }, "fast-glob": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.1.0.tgz", @@ -5002,6 +5008,12 @@ "universalify": "^0.1.0" } }, + "fs-monkey": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/fs-monkey/-/fs-monkey-0.3.3.tgz", + "integrity": "sha512-FNUvuTAJ3CqCQb5ELn+qCbGR/Zllhf2HtwsdAtBi59s1WeCjKMT81fHcSu7dwIskqGVK+MmOrb7VOBlq3/SItw==", + "dev": true + }, "fs-readdir-recursive": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz", @@ -8185,6 +8197,16 @@ "safe-buffer": "^5.1.2" } }, + "memfs": { + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/memfs/-/memfs-2.16.1.tgz", + "integrity": "sha512-hOUIxeXPuDeryPx1h+WxkBWJwWmd8f1lYXBdUMFMLEhxGGlaP6ri30eW9K4cMpbuizNsAwQe2SK3KyRa9qodXw==", + "dev": true, + "requires": { + "fast-extend": "0.0.2", + "fs-monkey": "^0.3.3" + } + }, "memory-fs": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.5.0.tgz", @@ -8606,9 +8628,9 @@ } }, "node-releases": { - "version": "1.1.40", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.40.tgz", - "integrity": "sha512-r4LPcC5b/bS8BdtWH1fbeK88ib/wg9aqmg6/s3ngNLn2Ewkn/8J6Iw3P9RTlfIAdSdvYvQl2thCY5Y+qTAQ2iQ==", + "version": "1.1.41", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.41.tgz", + "integrity": "sha512-+IctMa7wIs8Cfsa8iYzeaLTFwv5Y4r5jZud+4AnfymzeEXKBCavFX0KBgzVaPVqf0ywa6PrO8/b+bPqdwjGBSg==", "dev": true, "requires": { "semver": "^6.3.0" @@ -9659,9 +9681,9 @@ "dev": true }, "resolve": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", - "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.2.tgz", + "integrity": "sha512-cAVTI2VLHWYsGOirfeYVVQ7ZDejtQ9fp4YhYckWDEkFfqbVjaT11iM8k6xSAfGFMM+gDpZjMnFssPu8we+mqFw==", "dev": true, "requires": { "path-parse": "^1.0.6" @@ -11232,14 +11254,14 @@ } }, "url-loader": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/url-loader/-/url-loader-2.2.0.tgz", - "integrity": "sha512-G8nk3np8ZAnwhHXas1JxJEwJyQdqFXAKJehfgZ/XrC48volFBRtO+FIKtF2u0Ma3bw+4vnDVjHPAQYlF9p2vsw==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/url-loader/-/url-loader-2.3.0.tgz", + "integrity": "sha512-goSdg8VY+7nPZKUEChZSEtW5gjbS66USIGCeSJ1OVOJ7Yfuh/36YxCwMi5HVEJh6mqUYOoy3NJ0vlOMrWsSHog==", "dev": true, "requires": { "loader-utils": "^1.2.3", "mime": "^2.4.4", - "schema-utils": "^2.4.1" + "schema-utils": "^2.5.0" } }, "use": { diff --git a/package.json b/package.json index b8bf26a..8f14fca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "file-loader", - "version": "4.3.0", + "version": "5.0.0", "description": "A file loader module for webpack", "license": "MIT", "repository": "webpack-contrib/file-loader", @@ -9,32 +9,32 @@ "bugs": "https://github.com/webpack-contrib/file-loader/issues", "main": "dist/cjs.js", "engines": { - "node": ">= 8.9.0" + "node": ">= 10.13.0" }, "scripts": { "start": "npm run build -- -w", - "prebuild": "npm run clean", - "build": "cross-env NODE_ENV=production babel src -d dist --ignore \"src/**/*.test.js\" --copy-files", "clean": "del-cli dist", + "prebuild": "npm run clean", + "build": "cross-env NODE_ENV=production babel src -d dist --copy-files", "commitlint": "commitlint --from=master", - "lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css}\" --list-different", - "lint:js": "eslint --cache src test", - "lint": "npm-run-all -l -p \"lint:**\"", - "prepare": "npm run build", - "release": "standard-version", "security": "npm audit", + "lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different", + "lint:js": "eslint --cache .", + "lint": "npm-run-all -l -p \"lint:**\"", "test:only": "cross-env NODE_ENV=test jest", - "test:watch": "cross-env NODE_ENV=test jest --watch", - "test:coverage": "cross-env NODE_ENV=test jest --collectCoverageFrom=\"src/**/*.js\" --coverage", + "test:watch": "npm run test:only -- --watch", + "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage", "pretest": "npm run lint", - "test": "cross-env NODE_ENV=test npm run test:coverage", + "test": "npm run test:coverage", + "prepare": "npm run build", + "release": "standard-version", "defaults": "webpack-defaults" }, "files": [ "dist" ], "peerDependencies": { - "webpack": "^4.0.0" + "webpack": "^4.0.0 || ^5.0.0" }, "dependencies": { "loader-utils": "^1.2.3", @@ -46,7 +46,7 @@ "@babel/preset-env": "^7.7.1", "@commitlint/cli": "^8.2.0", "@commitlint/config-conventional": "^8.2.0", - "@webpack-contrib/defaults": "^5.0.2", + "@webpack-contrib/defaults": "^6.0.2", "@webpack-contrib/eslint-config-webpack": "^3.0.0", "babel-jest": "^24.9.0", "commitlint-azure-pipelines-cli": "^1.0.2", @@ -60,11 +60,12 @@ "jest": "^24.9.0", "jest-junit": "^9.0.0", "lint-staged": "^9.4.3", + "memfs": "^2.16.1", "memory-fs": "^0.5.0", "npm-run-all": "^4.1.5", "prettier": "^1.19.1", "standard-version": "^7.0.1", - "url-loader": "^2.2.0", + "url-loader": "^2.3.0", "webpack": "^4.41.2" }, "keywords": [ diff --git a/src/index.js b/src/index.js index 98c14c4..aad4a4e 100644 --- a/src/index.js +++ b/src/index.js @@ -59,9 +59,10 @@ export default function loader(content) { this.emitFile(outputPath, content); } - return `${ - options.esModules ? 'export default' : 'module.exports =' - } ${publicPath};`; + const esModules = + typeof options.esModules !== 'undefined' ? options.esModules : true; + + return `${esModules ? 'export default' : 'module.exports ='} ${publicPath};`; } export const raw = true; diff --git a/test/__snapshots__/context-option.test.js.snap b/test/__snapshots__/context-option.test.js.snap index 87e4e0c..e153a5d 100644 --- a/test/__snapshots__/context-option.test.js.snap +++ b/test/__snapshots__/context-option.test.js.snap @@ -1,3 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with \`context\` option matches snapshot for \`{String}\` value 1`] = `"module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";"`; +exports[`"context" option should work with "String" value: errors 1`] = `Array []`; + +exports[`"context" option should work with "String" value: result 1`] = `"test/fixtures/file.png"`; + +exports[`"context" option should work with "String" value: warnings 1`] = `Array []`; + +exports[`"context" option should work without value: errors 1`] = `Array []`; + +exports[`"context" option should work without value: result 1`] = `"fixtures/file.png"`; + +exports[`"context" option should work without value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/emitFile-option.test.js.snap b/test/__snapshots__/emitFile-option.test.js.snap index aa6a97d..b2a232d 100644 --- a/test/__snapshots__/emitFile-option.test.js.snap +++ b/test/__snapshots__/emitFile-option.test.js.snap @@ -1,3 +1,39 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with \`emitFile\` option matches snapshot for \`true\` (\`{Boolean}\`) (default) 1`] = `"64eababb117f90535085779cc0325003.svg"`; +exports[`"emitFile" option should work with "Boolean" value equal "false": assets 1`] = ` +Array [ + "main.bundle.js", +] +`; + +exports[`"emitFile" option should work with "Boolean" value equal "false": errors 1`] = `Array []`; + +exports[`"emitFile" option should work with "Boolean" value equal "false": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"emitFile" option should work with "Boolean" value equal "false": warnings 1`] = `Array []`; + +exports[`"emitFile" option should work with "Boolean" value equal "true": assets 1`] = ` +Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] +`; + +exports[`"emitFile" option should work with "Boolean" value equal "true": errors 1`] = `Array []`; + +exports[`"emitFile" option should work with "Boolean" value equal "true": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"emitFile" option should work with "Boolean" value equal "true": warnings 1`] = `Array []`; + +exports[`"emitFile" option should work without value: assets 1`] = ` +Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] +`; + +exports[`"emitFile" option should work without value: errors 1`] = `Array []`; + +exports[`"emitFile" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"emitFile" option should work without value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/esModules-option.test.js.snap b/test/__snapshots__/esModules-option.test.js.snap index c2ceda7..1a66ce5 100644 --- a/test/__snapshots__/esModules-option.test.js.snap +++ b/test/__snapshots__/esModules-option.test.js.snap @@ -1,28 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with \`esModules\` option matches snapshot for \`false\` value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`esModules\` option matches snapshot for \`true\` value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "export default __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`esModules\` option matches snapshot without value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"esModules" option should work with "Boolean" value equal "false": errors 1`] = `Array []`; + +exports[`"esModules" option should work with "Boolean" value equal "false": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"esModules" option should work with "Boolean" value equal "false": warnings 1`] = `Array []`; + +exports[`"esModules" option should work with "Boolean" value equal "true": errors 1`] = `Array []`; + +exports[`"esModules" option should work with "Boolean" value equal "true": result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"esModules" option should work with "Boolean" value equal "true": warnings 1`] = `Array []`; + +exports[`"esModules" option should work without value: errors 1`] = `Array []`; + +exports[`"esModules" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"esModules" option should work without value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index b047bc2..51ba83e 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -1,115 +1,52 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`loader should work with ModuleConcatenationPlugin 1`] = ` -"/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // create a fake namespace object -/******/ // mode & 1: value is a module id, require it -/******/ // mode & 2: merge all properties of value into the ns -/******/ // mode & 4: return value when already ns object -/******/ // mode & 8|1: behave like require -/******/ __webpack_require__.t = function(value, mode) { -/******/ if(mode & 1) value = __webpack_require__(value); -/******/ if(mode & 8) return value; -/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; -/******/ var ns = Object.create(null); -/******/ __webpack_require__.r(ns); -/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); -/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); -/******/ return ns; -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = \\"\\"; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -\\"use strict\\"; -__webpack_require__.r(__webpack_exports__); - -// CONCATENATED MODULE: ./file.png -/* harmony default export */ var file = (__webpack_require__.p + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\"); -// CONCATENATED MODULE: ./fixture.js -/* eslint-disable */ - - -/* harmony default export */ var fixture = __webpack_exports__[\\"default\\"] = (file); - - -/***/ }) -/******/ ]); -//# sourceMappingURL=main.bundle.js.map" +exports[`loader should work with "ModuleConcatenationPlugin" plugin: assets 1`] = ` +Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`loader should works with \`url-loader\` when limit is less 1`] = `"module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";"`; +exports[`loader should work with "ModuleConcatenationPlugin" plugin: errors 1`] = `Array []`; -exports[`loader should works with \`url-loader\` when limit is more 1`] = `"module.exports = \\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAAAXNSR0IArs4c6QAAGjNJREFUeAHtnQewFMXWx/uSxZxRUTGAAcyYnwpiJhgRFRCM6GeBZaklopaUWoUo9cwIqPhhAjGAWRQTRjAgijnnLOqnAgL3fv3rR+/r29uzO7t3e3Z2t0/V1uzM9Mx0n/nP6dPnnD4tRKDAgcCBwIFK4UCdq6JDhw5dZeHChRfKc4c2NDR0kNtWrnLhWE1woKGuru4X2dKX5fbym2666aU4rc4C1pAhQ/ZetmzZ7RJQG8W5QShTOxyQwKqXuPj3hhtueN7IkSPrc7W8uXny1FNPXa++vv55eXE783j4HziwnAMIoj3+T9Ibb7zxci6uNDNPSkk1VoJqdfNY+B84YHNAYuQyKYQ2s4+b+xlgyYJrSVHXxzwZ/gcORHCgjezZjos4pw630Cdlwa0kEjNA4/hqq60mLrzwQrXV5cK2tjggcSGmTp0qZs6caTe8s33A3DeBtLJ5gv8bbbRRAJXNlBrbb9asmejcORtDUm1q161bt8333XffDfr27buCzRYTWPa5sB84kJMDzZs3bybVpxV//fXXDQ8++OC1ZY+XsTIEYOVkXTgZlwP//PPP6gcddFBm4BeAFZdzoVxeDkh9bE3ZLSpjegBWXnaFAnE5IIFVJ7tFpasHYMXlWigXiwNS2W9NwQCsWOwKheJyoHXr1kqBD8CKy7FQriAOBGAVxK5QOC4HArDiciqUK4gDAVgFsSsUjsuBAKy4nArlCuJAAFZB7AqF43IgE90Q94JaKifdFGLRokVi6dKlolWrVqJNmzaiRYvAsjgYqFkuSe+8+OGHH8T333/f6LdgwQIFpsWLFwtCRmwCWNJWI1ZYYQWx1lpriXbt2jX6cSyQEDUDLOl5F19++aV4//331e/DDz8UgKdQQnrx++uvv8TPP/+s7mXeY9VVVxVbbLGF2HLLLdVvnXXWMU/XzP+qBhZgeu+998TLL78s5s2bJ/7++2/vL/b3338Xc+bMUT8etuaaa4qddtpJ7LHHHqJ9+/ben5+WB1QlsL799lvx0ksviVdeeUX89ttvZeX1L7/8Ip544gn1A1gAbNdddxVItmqmqgIW3dsjjzwi3nnnnZK8M3QprbBrRX7JkiVF3/vrr79WYb7333+/2G233cQhhxwiqrWrrApgzZ8/XwHqo48+Kuilr7zyyir8GgV83XXXVUo42xVXXFEp6DI6Mut+KP3oZnIGVCOln0EAOlwcvQ0d7YUXXlBStWvXrqJnz55igw02yHpWJR+oaGB99dVX4o477hCffPJJrHfASM5UrIvReWQ4rmjbtq36AcLtttsu82xA9+mnnyq9jkEC/wFRFDHqRB979dVXlQSTQXJilVVWiSpeUccrEljYlqZPny6efvppp0nAfAOYB7bddlul22yzzTYCYPgi7t2xY0f169Onj5BpChRoGDzkkqYMMvQA47DDDhPdu3cXLmnpq94+7ltxwOLrnjJlimD0lYvWW2890aNHD7Hzzjurri1XWV/nkJB77723+mGaYEDxzDPPqG7U9UxGrXfddZfqJgcNGiQ23nhjV7GKOFYxwEJ5vvPOO8WLL76Yk7FMWUMpZojv+urpPuX0cPHWW28pSXbooYfmvF+pTmI4RYrJCQfiueeeEzNmzIgcsaKrjRo1Shx55JFi//33L1UVEr1PRQAL88G4ceME2yhC+T3qqKME3Z1N2vzw+uuvi59++ilzGqU9acI1BFjo7lDgH3jgAacEQze7++67xQcffCBOOOGEskndYvmTemChe6CgR422MAcgCfbbbz/B5EqTGC0++eSTjcwPzO7eYYcdlERDkS8XofvJCZ+qq542bZqYNWuWU1988803xS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LW+iyuoRgFVlLzQtzQnASsubqLJ6mMDKSg6A8zZXsH+V8SI0x8EB7Hbkj7BJjor/tI+Z+xlzg/RXvS+D/eulfSYDNkDFrORAgQM2ByTgPraPmfsZEMnkEz9JUD1ongz/AwciOLBYLvrwUMQ5dTgDLPaktfl/pIhbkOuCcC5wQLq5rlqwYMFXuTjRCFgTJkz4ToLrMAmuL3NdFM7VJgckLuqlz/QWOa/zf/NxoBGwKCwnhM6S+tY28iZXyt+H8tA/+W4Szlc1Bxpk636VatLTsvs7Ti5acIX0jXIsJ+UNBJJJU9vKmKX2Oe8STgYOLOeABN2fcqb3t1kSy+aQnAoeJJbNlLAfyQE5WlzMybzAevbZZ5dKMfhX5J3CicCB5Rygi5Sx/soemhdYXCOnff8gA9bqAwcDB3JxQALrF7lEoOrh8upY+kboWtKA2k5Kr4xRVZ8L28ABGW69QE4U/lkO+JRiHxtYsK5v377N5chgDRm6u5L8tQzsrG0OSAzUSym1UM7h/FVKqoW1zY3Q+sCBwIHK5cD/A4bJawZvxvyKAAAAAElFTkSuQmCC\\""`; +exports[`loader should work with "ModuleConcatenationPlugin" plugin: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; -exports[`loader should works without options 1`] = `"module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";"`; +exports[`loader should work with "ModuleConcatenationPlugin" plugin: warnings 1`] = `Array []`; + +exports[`loader should work with "url-loader" when limit is less: assets 1`] = ` +Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] +`; + +exports[`loader should work with "url-loader" when limit is less: errors 1`] = `Array []`; + +exports[`loader should work with "url-loader" when limit is less: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`loader should work with "url-loader" when limit is less: warnings 1`] = `Array []`; + +exports[`loader should works with "url-loader" when limit is more: assets 1`] = ` +Array [ + "main.bundle.js", +] +`; + +exports[`loader should works with "url-loader" when limit is more: errors 1`] = `Array []`; + +exports[`loader should works with "url-loader" when limit is more: result 1`] = `"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAAAXNSR0IArs4c6QAAGjNJREFUeAHtnQewFMXWx/uSxZxRUTGAAcyYnwpiJhgRFRCM6GeBZaklopaUWoUo9cwIqPhhAjGAWRQTRjAgijnnLOqnAgL3fv3rR+/r29uzO7t3e3Z2t0/V1uzM9Mx0n/nP6dPnnD4tRKDAgcCBwIFK4UCdq6JDhw5dZeHChRfKc4c2NDR0kNtWrnLhWE1woKGuru4X2dKX5fbym2666aU4rc4C1pAhQ/ZetmzZ7RJQG8W5QShTOxyQwKqXuPj3hhtueN7IkSPrc7W8uXny1FNPXa++vv55eXE783j4HziwnAMIoj3+T9Ibb7zxci6uNDNPSkk1VoJqdfNY+B84YHNAYuQyKYQ2s4+b+xlgyYJrSVHXxzwZ/gcORHCgjezZjos4pw630Cdlwa0kEjNA4/hqq60mLrzwQrXV5cK2tjggcSGmTp0qZs6caTe8s33A3DeBtLJ5gv8bbbRRAJXNlBrbb9asmejcORtDUm1q161bt8333XffDfr27buCzRYTWPa5sB84kJMDzZs3bybVpxV//fXXDQ8++OC1ZY+XsTIEYOVkXTgZlwP//PPP6gcddFBm4BeAFZdzoVxeDkh9bE3ZLSpjegBWXnaFAnE5IIFVJ7tFpasHYMXlWigXiwNS2W9NwQCsWOwKheJyoHXr1kqBD8CKy7FQriAOBGAVxK5QOC4HArDiciqUK4gDAVgFsSsUjsuBAKy4nArlCuJAAFZB7AqF43IgE90Q94JaKifdFGLRokVi6dKlolWrVqJNmzaiRYvAsjgYqFkuSe+8+OGHH8T333/f6LdgwQIFpsWLFwtCRmwCWNJWI1ZYYQWx1lpriXbt2jX6cSyQEDUDLOl5F19++aV4//331e/DDz8UgKdQQnrx++uvv8TPP/+s7mXeY9VVVxVbbLGF2HLLLdVvnXXWMU/XzP+qBhZgeu+998TLL78s5s2bJ/7++2/vL/b3338Xc+bMUT8etuaaa4qddtpJ7LHHHqJ9+/ben5+WB1QlsL799lvx0ksviVdeeUX89ttvZeX1L7/8Ip544gn1A1gAbNdddxVItmqmqgIW3dsjjzwi3nnnnZK8M3QprbBrRX7JkiVF3/vrr79WYb7333+/2G233cQhhxwiqrWrrApgzZ8/XwHqo48+Kuilr7zyyir8GgV83XXXVUo42xVXXFEp6DI6Mut+KP3oZnIGVCOln0EAOlwcvQ0d7YUXXlBStWvXrqJnz55igw02yHpWJR+oaGB99dVX4o477hCffPJJrHfASM5UrIvReWQ4rmjbtq36AcLtttsu82xA9+mnnyq9jkEC/wFRFDHqRB979dVXlQSTQXJilVVWiSpeUccrEljYlqZPny6efvppp0nAfAOYB7bddlul22yzzTYCYPgi7t2xY0f169Onj5BpChRoGDzkkqYMMvQA47DDDhPdu3cXLmnpq94+7ltxwOLrnjJlimD0lYvWW2890aNHD7Hzzjurri1XWV/nkJB77723+mGaYEDxzDPPqG7U9UxGrXfddZfqJgcNGiQ23nhjV7GKOFYxwEJ5vvPOO8WLL76Yk7FMWUMpZojv+urpPuX0cPHWW28pSXbooYfmvF+pTmI4RYrJCQfiueeeEzNmzIgcsaKrjRo1Shx55JFi//33L1UVEr1PRQAL88G4ceME2yhC+T3qqKME3Z1N2vzw+uuvi59++ilzGqU9acI1BFjo7lDgH3jgAacEQze7++67xQcffCBOOOGEskndYvmTemChe6CgR422MAcgCfbbbz/B5EqTGC0++eSTjcwPzO7eYYcdlERDkS8XofvJCZ+qq542bZqYNWuWU1988803xSWXXCJOO+00sckmm5SrugU/N9XAevjhh5WSHtUqhurHHHNMo9naKMLoMnQ1WsIBPgyTu+yyi9hss82cXWTUM3wfx7QxYMAAseeee6oP6Isvvsh6JEbWMWPGKHC5JHLWBSk4kEpgAY7JkyerUZ+LRxgueRm77757o9MYSLkOPQpaY401lAKPAo0inWZCGo0YMUJgPMVSDw9MQmJff/31AqWejyTtlDpgYQuSWePEa6+95uQduhTdAqM+TXzR99xzT+YaFOXDDz9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t+H8tA/+W4Szlc1Bxpk636VatLTsvs7Ti5acIX0jXIsJ+UNBJJJU9vKmKX2Oe8STgYOLOeABN2fcqb3t1kSy+aQnAoeJJbNlLAfyQE5WlzMybzAevbZZ5dKMfhX5J3CicCB5Rygi5Sx/soemhdYXCOnff8gA9bqAwcDB3JxQALrF7lEoOrh8upY+kboWtKA2k5Kr4xRVZ8L28ABGW69QE4U/lkO+JRiHxtYsK5v377N5chgDRm6u5L8tQzsrG0OSAzUSym1UM7h/FVKqoW1zY3Q+sCBwIHK5cD/A4bJawZvxvyKAAAAAElFTkSuQmCC"`; + +exports[`loader should works with "url-loader" when limit is more: warnings 1`] = `Array []`; + +exports[`loader should works without options: assets 1`] = ` +Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] +`; + +exports[`loader should works without options: errors 1`] = `Array []`; + +exports[`loader should works without options: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`loader should works without options: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/name-option.test.js.snap b/test/__snapshots__/name-option.test.js.snap index 10e41a4..f9679db 100644 --- a/test/__snapshots__/name-option.test.js.snap +++ b/test/__snapshots__/name-option.test.js.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with \`name\` option matches snapshot for \`{Function}\` value 1`] = `"module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";"`; +exports[`"name" option should work with "Function" value: errors 1`] = `Array []`; -exports[`when applied with \`name\` option matches snapshot for \`{String}\` value 1`] = `"module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";"`; +exports[`"name" option should work with "Function" value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.function.png"`; + +exports[`"name" option should work with "Function" value: warnings 1`] = `Array []`; + +exports[`"name" option should work with "String" value: errors 1`] = `Array []`; + +exports[`"name" option should work with "String" value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.string.png"`; + +exports[`"name" option should work with "String" value: warnings 1`] = `Array []`; + +exports[`"name" option should work without value: errors 1`] = `Array []`; + +exports[`"name" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"name" option should work without value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/outputPath-option.test.js.snap b/test/__snapshots__/outputPath-option.test.js.snap index fd13711..67a24ae 100644 --- a/test/__snapshots__/outputPath-option.test.js.snap +++ b/test/__snapshots__/outputPath-option.test.js.snap @@ -1,118 +1,144 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with \`outputPath\` option matches snapshot for \`{Function}\` value 1`] = ` -Object { - "assets": Array [ - "output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "Function" value and with "name" option: assets 1`] = ` +Array [ + "output_path_func/file.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{Function}\` value and pass \`context\` 1`] = ` -Object { - "assets": Array [ - "output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"outputPath" option should work with "Function" value and with "name" option: errors 1`] = `Array []`; -exports[`when applied with \`outputPath\` option matches snapshot for \`{Function}\` value and pass \`resourcePath\` 1`] = ` -Object { - "assets": Array [ - "output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"outputPath" option should work with "Function" value and with "name" option: result 1`] = `"output_path_func/file.png"`; + +exports[`"outputPath" option should work with "Function" value and with "name" option: warnings 1`] = `Array []`; -exports[`when applied with \`outputPath\` option matches snapshot for \`{Function}\` value with \`options.name\` 1`] = ` -Object { - "assets": Array [ - "output_path_func/file.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"output_path_func/file.png\\";", -} +exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": assets 1`] = ` +Array [ + "output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{Function}\` value with \`publicPath\` (\`{Function}\`) 1`] = ` -Object { - "assets": Array [ - "output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": result 1`] = `"public_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work with "Function" value and with "publicPath" as "Function": warnings 1`] = `Array []`; + +exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": assets 1`] = ` +Array [ + "output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{Function}\` value with \`publicPath\` (\`{String}\`) 1`] = ` -Object { - "assets": Array [ - "output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work with "Function" value and with "publicPath" as "String": warnings 1`] = `Array []`; + +exports[`"outputPath" option should work with "Function" value: assets 1`] = ` +Array [ + "output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{String}\` value 1`] = ` -Object { - "assets": Array [ - "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "Function" value: errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "Function" value: result 1`] = `"output_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work with "Function" value: warnings 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value and with "name" option: assets 1`] = ` +Array [ + "output_path/file.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{String}\` value with \`publicPath\` (\`{Function}\`) 1`] = ` -Object { - "assets": Array [ - "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "String" value and with "name" option: errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value and with "name" option: result 1`] = `"output_path/file.png"`; + +exports[`"outputPath" option should work with "String" value and with "name" option: warnings 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": assets 1`] = ` +Array [ + "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{String}\` value with \`publicPath\` (\`{String}\`) 1`] = ` -Object { - "assets": Array [ - "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": result 1`] = `"public_path_func/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" as "Function": warnings 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: assets 1`] = ` +Array [ + "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{String}\` value with \`publicPath\` (\`{String}\`) without trailing slash 1`] = ` -Object { - "assets": Array [ - "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" option and without trailing slash: warnings 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" option: assets 1`] = ` +Array [ + "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{String}\` value without trailing slash 1`] = ` -Object { - "assets": Array [ - "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "String" value and with "publicPath" option: errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" option: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work with "String" value and with "publicPath" option: warnings 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value without trailing slash: assets 1`] = ` +Array [ + "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot for \`{String}\` with \`name\` option 1`] = ` -Object { - "assets": Array [ - "output_path/file.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"output_path/file.png\\";", -} +exports[`"outputPath" option should work with "String" value without trailing slash: errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value without trailing slash: result 1`] = `"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work with "String" value without trailing slash: warnings 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value: assets 1`] = ` +Array [ + "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; -exports[`when applied with \`outputPath\` option matches snapshot without value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} +exports[`"outputPath" option should work with "String" value: errors 1`] = `Array []`; + +exports[`"outputPath" option should work with "String" value: result 1`] = `"output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work with "String" value: warnings 1`] = `Array []`; + +exports[`"outputPath" option should work without value: assets 1`] = ` +Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "main.bundle.js", +] `; + +exports[`"outputPath" option should work without value: errors 1`] = `Array []`; + +exports[`"outputPath" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"outputPath" option should work without value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/postTransformPublicPath-option.test.js.snap b/test/__snapshots__/postTransformPublicPath-option.test.js.snap index 17e1e99..f4d9a77 100644 --- a/test/__snapshots__/postTransformPublicPath-option.test.js.snap +++ b/test/__snapshots__/postTransformPublicPath-option.test.js.snap @@ -1,82 +1,55 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with \`postTransformPublicPath\` option matches snapshot for appending to input parameter value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"/test\\";", -} -`; - -exports[`when applied with \`postTransformPublicPath\` option matches snapshot for returned input parameter value without modification 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for appending to input parameter value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"?test=test\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for prefixing with __webpack_public_path__ 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for prefixing with string 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"path_prefix/\\" + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for returned input parameter value without modification 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for appending to input parameter value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"?test=test\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for prefixing with __webpack_public_path__ 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for returned input parameter value without modification 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"postTransformPublicPath" option should work with "Function" and "publicPath" option as "Function": errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" and "publicPath" option as "Function": result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"postTransformPublicPath" option should work with "Function" and "publicPath" option as "Function": warnings 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and "publicPath" option as "Function": errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and "publicPath" option as "Function": result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png?test=test"`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and "publicPath" option as "Function": warnings 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and use "publicPath" option: errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and use "publicPath" option: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png?test=test"`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value and use "publicPath" option: warnings 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value: errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png/test"`; + +exports[`"postTransformPublicPath" option should work with "Function" where append to input parameter value: warnings 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where prepend "__webpack_public_path__" and "publicPath" option as "String": errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where prepend "__webpack_public_path__" and "publicPath" option as "String": result 1`] = `"http://code.com/public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"postTransformPublicPath" option should work with "Function" where prepend "__webpack_public_path__" and "publicPath" option as "String": warnings 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where prepend path and "publicPath" option as "String": errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where prepend path and "publicPath" option as "String": result 1`] = `"path_prefix/public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"postTransformPublicPath" option should work with "Function" where prepend path and "publicPath" option as "String": warnings 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification and use "publicPath" option: errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification and use "publicPath" option: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification and use "publicPath" option: warnings 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification: errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"postTransformPublicPath" option should work with "Function" where return input parameter value without modification: warnings 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work without value: errors 1`] = `Array []`; + +exports[`"postTransformPublicPath" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"postTransformPublicPath" option should work without value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/publicPath-option.test.js.snap b/test/__snapshots__/publicPath-option.test.js.snap index 676eeba..539538c 100644 --- a/test/__snapshots__/publicPath-option.test.js.snap +++ b/test/__snapshots__/publicPath-option.test.js.snap @@ -1,64 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with \`publicPath\` option matches snapshot for \`{Function}\` value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"publicPath" option should work with "Function" value and pass "url", "resourcePath" and "context" as arguments: errors 1`] = `Array []`; -exports[`when applied with \`publicPath\` option matches snapshot for \`{Function}\` value and pass \`context\` 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"publicPath" option should work with "Function" value and pass "url", "resourcePath" and "context" as arguments: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; -exports[`when applied with \`publicPath\` option matches snapshot for \`{Function}\` value and pass \`resourcePath\` 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"publicPath" option should work with "Function" value and pass "url", "resourcePath" and "context" as arguments: warnings 1`] = `Array []`; -exports[`when applied with \`publicPath\` option matches snapshot for \`{String}\` value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"publicPath" option should work with "String" value equal an URL: errors 1`] = `Array []`; -exports[`when applied with \`publicPath\` option matches snapshot for \`{String}\` value as URL 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"https://cdn.com/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"publicPath" option should work with "String" value equal an URL: result 1`] = `"https://cdn.com/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; -exports[`when applied with \`publicPath\` option matches snapshot for \`{String}\` value without trailing slash 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"publicPath" option should work with "String" value equal an URL: warnings 1`] = `Array []`; -exports[`when applied with \`publicPath\` option matches snapshot without value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; +exports[`"publicPath" option should work with "String" value without trailing slash: errors 1`] = `Array []`; + +exports[`"publicPath" option should work with "String" value without trailing slash: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"publicPath" option should work with "String" value without trailing slash: warnings 1`] = `Array []`; + +exports[`"publicPath" option should work with "String" value: errors 1`] = `Array []`; + +exports[`"publicPath" option should work with "String" value: result 1`] = `"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"publicPath" option should work with "String" value: warnings 1`] = `Array []`; + +exports[`"publicPath" option should work without value: errors 1`] = `Array []`; + +exports[`"publicPath" option should work without value: result 1`] = `"9c87cbf3ba33126ffd25ae7f2f6bbafb.png"`; + +exports[`"publicPath" option should work without value: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/validation-options.test.js.snap b/test/__snapshots__/validate-options.test.js.snap similarity index 78% rename from test/__snapshots__/validation-options.test.js.snap rename to test/__snapshots__/validate-options.test.js.snap index 6d72c36..2246fd2 100644 --- a/test/__snapshots__/validation-options.test.js.snap +++ b/test/__snapshots__/validate-options.test.js.snap @@ -1,6 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`validate options 1`] = ` +exports[`validate options should throw an error on the "context" option with "true" value 1`] = ` +"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. + - options.context should be a string. + -> A custom file context (https://github.com/webpack-contrib/file-loader#context)." +`; + +exports[`validate options should throw an error on the "emitFile" option with "true" value 1`] = ` +"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. + - options.emitFile should be a boolean. + -> Enables/Disables emit files (https://github.com/webpack-contrib/file-loader#emitfile)." +`; + +exports[`validate options should throw an error on the "esModules" option with "true" value 1`] = ` +"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. + - options.esModules should be a boolean." +`; + +exports[`validate options should throw an error on the "name" option with "true" value 1`] = ` "Invalid options object. File Loader has been initialised using an options object that does not match the API schema. - options.name should be one of these: string | function @@ -10,7 +27,7 @@ exports[`validate options 1`] = ` * options.name should be an instance of function." `; -exports[`validate options 2`] = ` +exports[`validate options should throw an error on the "outputPath" option with "true" value 1`] = ` "Invalid options object. File Loader has been initialised using an options object that does not match the API schema. - options.outputPath should be one of these: string | function @@ -20,7 +37,7 @@ exports[`validate options 2`] = ` * options.outputPath should be an instance of function." `; -exports[`validate options 3`] = ` +exports[`validate options should throw an error on the "publicPath" option with "true" value 1`] = ` "Invalid options object. File Loader has been initialised using an options object that does not match the API schema. - options.publicPath should be one of these: string | function @@ -30,19 +47,7 @@ exports[`validate options 3`] = ` * options.publicPath should be an instance of function." `; -exports[`validate options 4`] = ` -"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. - - options.context should be a string. - -> A custom file context (https://github.com/webpack-contrib/file-loader#context)." -`; - -exports[`validate options 5`] = ` -"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. - - options.emitFile should be a boolean. - -> Enables/Disables emit files (https://github.com/webpack-contrib/file-loader#emitfile)." -`; - -exports[`validate options 6`] = ` +exports[`validate options should throw an error on the "regExp" option with "true" value 1`] = ` "Invalid options object. File Loader has been initialised using an options object that does not match the API schema. - options.regExp should be one of these: string | RegExp @@ -51,8 +56,3 @@ exports[`validate options 6`] = ` * options.regExp should be a string. * options.regExp should be an instance of RegExp." `; - -exports[`validate options 7`] = ` -"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. - - options.esModules should be a boolean." -`; diff --git a/test/cjs.test.js b/test/cjs.test.js index 9e913dd..c923e34 100644 --- a/test/cjs.test.js +++ b/test/cjs.test.js @@ -1,12 +1,12 @@ -import loader from '../src'; -import CJSLoader from '../src/cjs'; +import src from '../src'; +import cjs from '../src/cjs'; describe('CJS', () => { it('should export loader', () => { - expect(CJSLoader).toEqual(loader); + expect(cjs).toEqual(src); }); - it('should export `raw` flag', () => { - expect(CJSLoader.raw).toEqual(true); + it('should export "raw" flag', () => { + expect(cjs.raw).toEqual(true); }); }); diff --git a/test/context-option.test.js b/test/context-option.test.js index 64551db..3fcbc7c 100644 --- a/test/context-option.test.js +++ b/test/context-option.test.js @@ -1,20 +1,43 @@ -import webpack from './helpers/compiler'; +import path from 'path'; -describe('when applied with `context` option', () => { - it('matches snapshot for `{String}` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - context: `${__dirname}`, - }, - }, - }; +import { + compile, + execute, + getCompiler, + normalizeErrors, + readAsset, +} from './helpers'; - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { source } = module; +describe('"context" option', () => { + it('should work without value', async () => { + const compiler = getCompiler('simple.js', { + name: '[path][name].[ext]', + context: __dirname, + }); + const stats = await compile(compiler); - expect(source).toMatchSnapshot(); + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + }); + + it('should work with "String" value', async () => { + const compiler = getCompiler('simple.js', { + name: '[path][name].[ext]', + context: path.resolve(__dirname, '../'), + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); }); diff --git a/test/emitFile-option.test.js b/test/emitFile-option.test.js index 065c4df..eba57dc 100644 --- a/test/emitFile-option.test.js +++ b/test/emitFile-option.test.js @@ -1,38 +1,55 @@ -import webpack from './helpers/compiler'; +import { + compile, + execute, + getCompiler, + normalizeErrors, + readAsset, +} from './helpers'; -describe('when applied with `emitFile` option', () => { - it('matches snapshot for `true` (`{Boolean}`) (default)', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - emitFile: true, - }, - }, - }; +describe('"emitFile" option', () => { + it('should work without value', async () => { + const compiler = getCompiler('simple.js'); + const stats = await compile(compiler); - const stats = await webpack('emitFile/fixture.js', config); - const [, module] = stats.toJson().modules; - const { assets } = module; - - expect(assets[0]).toMatchSnapshot(); + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `false` value (`{Boolean}`)', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - emitFile: false, - }, - }, - }; + it('should work with "Boolean" value equal "true"', async () => { + const compiler = getCompiler('simple.js', { + emitFile: true, + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + }); - const stats = await webpack('emitFile/fixture.js', config); - const [module] = stats.toJson().modules; - const { assets } = module; + it('should work with "Boolean" value equal "false"', async () => { + const compiler = getCompiler('simple.js', { + emitFile: false, + }); + const stats = await compile(compiler); - // eslint-disable-next-line no-undefined - expect(assets[0]).toBe(undefined); + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); }); diff --git a/test/esModules-option.test.js b/test/esModules-option.test.js index ddf6378..5ef4091 100644 --- a/test/esModules-option.test.js +++ b/test/esModules-option.test.js @@ -1,51 +1,52 @@ -import webpack from './helpers/compiler'; - -describe('when applied with `esModules` option', () => { - it('matches snapshot without value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); +import { + compile, + execute, + getCompiler, + normalizeErrors, + readAsset, +} from './helpers'; + +describe('"esModules" option', () => { + it('should work without value', async () => { + const compiler = getCompiler('simple.js'); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `true` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - esModules: true, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Boolean" value equal "true"', async () => { + const compiler = getCompiler('simple.js', { + esModules: true, + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `false` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - esModules: false, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Boolean" value equal "false"', async () => { + const compiler = getCompiler('simple.js', { + esModules: false, + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); }); diff --git a/test/fixtures/emitFile/fixture.js b/test/fixtures/emitFile/fixture.js deleted file mode 100644 index 7f78458..0000000 --- a/test/fixtures/emitFile/fixture.js +++ /dev/null @@ -1,4 +0,0 @@ -/* eslint-disable */ -import svg from '../file.svg'; - -export default svg diff --git a/test/fixtures/file.gif b/test/fixtures/file.gif deleted file mode 100644 index 2c192da..0000000 Binary files a/test/fixtures/file.gif and /dev/null differ diff --git a/test/fixtures/file.jpg b/test/fixtures/file.jpg deleted file mode 100644 index 8deb3d2..0000000 Binary files a/test/fixtures/file.jpg and /dev/null differ diff --git a/test/fixtures/file.svg b/test/fixtures/file.svg deleted file mode 100644 index f083f3f..0000000 --- a/test/fixtures/file.svg +++ /dev/null @@ -1,48 +0,0 @@ - - - - mochi - Created with Sketch. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/fixtures/nested/assets/file.png b/test/fixtures/nested/assets/file.png deleted file mode 100644 index 02d7a6b..0000000 Binary files a/test/fixtures/nested/assets/file.png and /dev/null differ diff --git a/test/fixtures/nested/fixture.js b/test/fixtures/nested/fixture.js deleted file mode 100644 index af5f4ed..0000000 --- a/test/fixtures/nested/fixture.js +++ /dev/null @@ -1,4 +0,0 @@ -/* eslint-disable */ -import png from './assets/file.png'; - -export default png; diff --git a/test/fixtures/fixture.js b/test/fixtures/simple.js similarity index 79% rename from test/fixtures/fixture.js rename to test/fixtures/simple.js index 666d017..f1a0830 100644 --- a/test/fixtures/fixture.js +++ b/test/fixtures/simple.js @@ -1,4 +1,6 @@ /* eslint-disable */ import png from './file.png'; +__export__ = png; + export default png; diff --git a/test/helpers/compile.js b/test/helpers/compile.js new file mode 100644 index 0000000..066873a --- /dev/null +++ b/test/helpers/compile.js @@ -0,0 +1,11 @@ +export default (compiler) => { + return new Promise((resolve, reject) => { + compiler.run((error, stats) => { + if (error) { + return reject(error); + } + + return resolve(stats); + }); + }); +}; diff --git a/test/helpers/compiler.js b/test/helpers/compiler.js deleted file mode 100644 index cb1ece4..0000000 --- a/test/helpers/compiler.js +++ /dev/null @@ -1,72 +0,0 @@ -/* eslint-disable - import/order, - multiline-ternary, - no-param-reassign, -*/ -import del from 'del'; -import path from 'path'; -import webpack from 'webpack'; -import MemoryFS from 'memory-fs'; - -const module = (config) => { - return { - rules: config.rules - ? config.rules - : config.loader - ? [ - { - test: (config.loader && config.loader.test) || /\.txt$/, - use: { - loader: path.resolve(__dirname, '../../src'), - options: (config.loader && config.loader.options) || {}, - }, - }, - ] - : [], - }; -}; - -const plugins = (config) => [].concat(config.plugins || []); - -const output = (config) => { - return { - path: path.resolve( - __dirname, - `../outputs/${config.output ? config.output : ''}` - ), - filename: '[name].bundle.js', - }; -}; - -export default function(fixture, config, options) { - // webpack Config - config = { - mode: config.mode || 'development', - devtool: config.devtool || 'sourcemap', - context: path.resolve(__dirname, '..', 'fixtures'), - entry: `./${fixture}`, - output: output(config), - module: module(config), - plugins: plugins(config), - optimization: { - minimize: false, - runtimeChunk: false, - }, - }; - // Compiler Options - options = Object.assign({ output: false }, options); - - if (options.output) del.sync(config.output.path); - - const compiler = webpack(config); - - if (!options.output) compiler.outputFileSystem = new MemoryFS(); - - return new Promise((resolve, reject) => - compiler.run((err, stats) => { - if (err) reject(err); - - resolve(stats); - }) - ); -} diff --git a/test/helpers/execute.js b/test/helpers/execute.js new file mode 100644 index 0000000..866001a --- /dev/null +++ b/test/helpers/execute.js @@ -0,0 +1,22 @@ +import Module from 'module'; +import path from 'path'; + +const parentModule = module; + +export default (code) => { + const resource = 'test.js'; + const module = new Module(resource, parentModule); + // eslint-disable-next-line no-underscore-dangle + module.paths = Module._nodeModulePaths( + path.resolve(__dirname, '../fixtures') + ); + module.filename = resource; + + // eslint-disable-next-line no-underscore-dangle + module._compile( + `let __export__;${code};module.exports = __export__;`, + resource + ); + + return module.exports; +}; diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js new file mode 100644 index 0000000..b1e6350 --- /dev/null +++ b/test/helpers/getCompiler.js @@ -0,0 +1,45 @@ +import path from 'path'; + +import webpack from 'webpack'; +import { createFsFromVolume, Volume } from 'memfs'; + +export default (fixture, loaderOptions = {}, config = {}) => { + const fullConfig = { + mode: 'development', + devtool: config.devtool || false, + context: path.resolve(__dirname, '../fixtures'), + entry: path.resolve(__dirname, '../fixtures', fixture), + output: { + path: path.resolve(__dirname, '../outputs'), + filename: '[name].bundle.js', + chunkFilename: '[name].chunk.js', + }, + module: { + rules: [ + { + test: /(png|jpg|svg)/i, + rules: [ + { + loader: path.resolve(__dirname, '../../src'), + options: loaderOptions || {}, + }, + ], + }, + ], + }, + plugins: [], + ...config, + }; + + const compiler = webpack(fullConfig); + + if (!config.outputFileSystem) { + const outputFileSystem = createFsFromVolume(new Volume()); + // Todo remove when we drop webpack@4 support + outputFileSystem.join = path.join.bind(path); + + compiler.outputFileSystem = outputFileSystem; + } + + return compiler; +}; diff --git a/test/helpers/index.js b/test/helpers/index.js new file mode 100644 index 0000000..afe19df --- /dev/null +++ b/test/helpers/index.js @@ -0,0 +1,7 @@ +import compile from './compile'; +import execute from './execute'; +import getCompiler from './getCompiler'; +import normalizeErrors from './normalizeErrors'; +import readAsset from './readAsset'; + +export { compile, execute, getCompiler, normalizeErrors, readAsset }; diff --git a/test/helpers/normalizeErrors.js b/test/helpers/normalizeErrors.js new file mode 100644 index 0000000..d540ed7 --- /dev/null +++ b/test/helpers/normalizeErrors.js @@ -0,0 +1,25 @@ +function removeCWD(str) { + const isWin = process.platform === 'win32'; + let cwd = process.cwd(); + + if (isWin) { + // eslint-disable-next-line no-param-reassign + str = str.replace(/\\/g, '/'); + // eslint-disable-next-line no-param-reassign + cwd = cwd.replace(/\\/g, '/'); + } + + return str.replace(new RegExp(cwd, 'g'), ''); +} + +export default (errors) => { + return errors.map((error) => + removeCWD( + error + .toString() + .split('\n') + .slice(0, 2) + .join('\n') + ) + ); +}; diff --git a/test/helpers/readAsset.js b/test/helpers/readAsset.js new file mode 100644 index 0000000..1a36027 --- /dev/null +++ b/test/helpers/readAsset.js @@ -0,0 +1,15 @@ +import path from 'path'; + +export default (asset, compiler, stats) => { + const usedFs = compiler.outputFileSystem; + const outputPath = stats.compilation.outputOptions.path; + let data = ''; + + try { + data = usedFs.readFileSync(path.join(outputPath, asset)).toString(); + } catch (error) { + data = error.toString(); + } + + return data; +}; diff --git a/test/loader.test.js b/test/loader.test.js index 05aa851..5df92b7 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -1,99 +1,120 @@ -import webpack from './helpers/compiler'; +import { + compile, + execute, + getCompiler, + normalizeErrors, + readAsset, +} from './helpers'; describe('loader', () => { it('should works without options', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: {}, - }, - }; + const compiler = getCompiler('simple.js'); + const stats = await compile(compiler); - const stats = await webpack('fixture.js', config); - const jsonStats = stats.toJson(); - const { modules, assets } = jsonStats; - const [{ source }] = modules; - - // eslint-disable-next-line no-new-func - const assetName = new Function( - 'exports', - 'require', - 'module', - '__filename', - '__dirname', - `'use strict'\nvar __webpack_public_path__ = '';\nreturn ${source}` - )(exports, require, module, __filename, __dirname); - const hasModuleAsAsset = Boolean( - assets.find((asset) => asset.name === assetName) + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' ); - - expect(hasModuleAsAsset).toBe(true); - expect(source).toMatchSnapshot(); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('should works with `url-loader` when limit is less', async () => { - const config = { - rules: [ - { - test: /\.(png|jpg|gif)$/i, - use: [ + it('should work with "url-loader" when limit is less', async () => { + const compiler = getCompiler( + 'simple.js', + {}, + { + module: { + rules: [ { - loader: 'url-loader', - options: { - limit: 1, - }, + test: /(png|jpg|svg)/i, + rules: [ + { + loader: 'url-loader', + options: { + limit: 1, + }, + }, + ], }, ], }, - ], - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { source } = module; + } + ); + const stats = await compile(compiler); - expect(source).toMatchSnapshot(); + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('should works with `url-loader` when limit is more', async () => { - const config = { - rules: [ - { - test: /\.(png|jpg|gif)$/i, - use: [ + it('should works with "url-loader" when limit is more', async () => { + const compiler = getCompiler( + 'simple.js', + {}, + { + module: { + rules: [ { - loader: 'url-loader', - options: { - limit: 8192, - }, + test: /(png|jpg|svg)/i, + rules: [ + { + loader: 'url-loader', + options: { + limit: 8192, + }, + }, + ], }, ], }, - ], - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { source } = module; + } + ); + const stats = await compile(compiler); - expect(source).toMatchSnapshot(); + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('should work with ModuleConcatenationPlugin', async () => { - const config = { - mode: 'production', - loader: { - test: /(png|jpg|svg)/, - options: { - esModules: true, + it('should work with "ModuleConcatenationPlugin" plugin', async () => { + const compiler = getCompiler( + 'simple.js', + {}, + { + mode: 'production', + optimization: { + minimize: false, }, - }, - }; - - const stats = await webpack('fixture.js', config); + } + ); + const stats = await compile(compiler); expect( - stats.compilation.assets['main.bundle.js'].source() - ).toMatchSnapshot(); + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + + if (stats.compilation.modules.size) { + expect(stats.compilation.modules.size).toBe(2); + } else { + expect(stats.compilation.modules.length).toBe(1); + } }); }); diff --git a/test/name-option.test.js b/test/name-option.test.js index 14fd84e..1f46850 100644 --- a/test/name-option.test.js +++ b/test/name-option.test.js @@ -1,39 +1,54 @@ -import webpack from './helpers/compiler'; +import { + compile, + execute, + getCompiler, + normalizeErrors, + readAsset, +} from './helpers'; -describe('when applied with `name` option', () => { - it('matches snapshot for `{String}` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - name: '[hash].[ext]', - }, - }, - }; +describe('"name" option', () => { + it('should work without value', async () => { + const compiler = getCompiler('simple.js'); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + }); - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { source } = module; + it('should work with "String" value', async () => { + const compiler = getCompiler('simple.js', { + name: '[hash].string.[ext]', + }); + const stats = await compile(compiler); - expect(source).toMatchSnapshot(); + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{Function}` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - name() { - return '[hash].[ext]'; - }, - }, + it('should work with "Function" value', async () => { + const compiler = getCompiler('simple.js', { + name() { + return '[hash].function.[ext]'; }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { source } = module; + }); + const stats = await compile(compiler); - expect(source).toMatchSnapshot(); + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); }); diff --git a/test/outputPath-option.test.js b/test/outputPath-option.test.js index 9905584..0d44d48 100644 --- a/test/outputPath-option.test.js +++ b/test/outputPath-option.test.js @@ -1,248 +1,207 @@ -import webpack from './helpers/compiler'; - -describe('when applied with `outputPath` option', () => { - it('matches snapshot without value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); +import { + compile, + execute, + getCompiler, + normalizeErrors, + readAsset, +} from './helpers'; + +describe('"outputPath" option', () => { + it('should work without value', async () => { + const compiler = getCompiler('simple.js'); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath: 'output_path/', - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "String" value', async () => { + const compiler = getCompiler('simple.js', { + outputPath: 'output_path/', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` value without trailing slash', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath: 'output_path', - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "String" value without trailing slash', async () => { + const compiler = getCompiler('simple.js', { + outputPath: 'output_path', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` with `name` option', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - name: '[path][name].[ext]', - outputPath: 'output_path/', - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "String" value and with "name" option', async () => { + const compiler = getCompiler('simple.js', { + name: '[path][name].[ext]', + outputPath: 'output_path/', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{Function}` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath(url) { - return `output_path_func/${url}`; - }, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; + it('should work with "Function" value', async () => { + // TODO + const compiler = getCompiler('simple.js', { + outputPath(url, resourcePath, context) { + expect(url).toBe('9c87cbf3ba33126ffd25ae7f2f6bbafb.png'); + expect(resourcePath).toMatch('file.png'); + expect(context).toMatch('fixtures'); - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for `{Function}` value with `options.name`', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - name: '[name].[ext]', - outputPath(url) { - return `output_path_func/${url}`; - }, - }, + return `output_path_func/${url}`; }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` value with `publicPath` (`{String}`)', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath: 'output_path/', - publicPath: 'public_path/', - }, + it('should work with "Function" value and with "name" option', async () => { + const compiler = getCompiler('simple.js', { + name: '[name].[ext]', + outputPath(url) { + return `output_path_func/${url}`; }, - }; - - const stats = await webpack('nested/fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` value with `publicPath` (`{String}`) without trailing slash', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath: 'output_path', - publicPath: 'public_path', - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "String" value and with "publicPath" option', async () => { + const compiler = getCompiler('simple.js', { + outputPath: 'output_path/', + publicPath: 'public_path/', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{Function}` value with `publicPath` (`{String}`)', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - outputPath(url) { - return `output_path_func/${url}`; - }, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "String" value and with "publicPath" option and without trailing slash', async () => { + const compiler = getCompiler('simple.js', { + outputPath: 'output_path', + publicPath: 'public_path', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` value with `publicPath` (`{Function}`)', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath: 'output_path/', - publicPath(url) { - return `public_path_func/${url}`; - }, - }, + it('should work with "Function" value and with "publicPath" as "String"', async () => { + const compiler = getCompiler('simple.js', { + publicPath: 'public_path/', + outputPath(url) { + return `output_path_func/${url}`; }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{Function}` value with `publicPath` (`{Function}`)', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath(url) { - return `output_path_func/${url}`; - }, - publicPath(url) { - return `public_path_func/${url}`; - }, - }, + it('should work with "String" value and with "publicPath" as "Function"', async () => { + const compiler = getCompiler('simple.js', { + publicPath(url) { + return `public_path_func/${url}`; }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + outputPath: 'output_path/', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{Function}` value and pass `resourcePath`', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath(url, resourcePath) { - expect(resourcePath).toMatch('file.png'); - - return `output_path_func/${url}`; - }, - }, + it('should work with "Function" value and with "publicPath" as "Function"', async () => { + const compiler = getCompiler('simple.js', { + outputPath(url) { + return `output_path_func/${url}`; }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for `{Function}` value and pass `context`', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - outputPath(url, resourcePath, context) { - expect(context).toMatch('fixtures'); - - return `output_path_func/${url}`; - }, - }, + publicPath(url) { + return `public_path_func/${url}`; }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(Object.keys(stats.compilation.assets)).toMatchSnapshot('assets'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); }); diff --git a/test/postTransformPublicPath-option.test.js b/test/postTransformPublicPath-option.test.js index d673e02..e634a19 100644 --- a/test/postTransformPublicPath-option.test.js +++ b/test/postTransformPublicPath-option.test.js @@ -1,173 +1,165 @@ -import webpack from './helpers/compiler'; - -describe('when applied with `postTransformPublicPath` option', () => { - it('matches snapshot for returned input parameter value without modification', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - postTransformPublicPath: (p) => p, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); +import path from 'path'; + +import { + compile, + execute, + getCompiler, + normalizeErrors, + readAsset, +} from './helpers'; + +describe('"postTransformPublicPath" option', () => { + it('should work without value', async () => { + const compiler = getCompiler('simple.js'); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for appending to input parameter value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - postTransformPublicPath: (p) => `${p} + "/test"`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Function" where return input parameter value without modification', async () => { + const compiler = getCompiler('simple.js', { + postTransformPublicPath: (p) => p, + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); -}); -describe('when applied with `publicPath` and `postTransformPublicPath` option', () => { - describe('`{String}` value', () => { - it('matches snapshot for returned input parameter value without modification', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => p, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Function" where append to input parameter value', async () => { + const compiler = getCompiler('simple.js', { + postTransformPublicPath: (p) => `${p} + "/test"`, }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + }); - it('matches snapshot for appending to input parameter value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => `${p} + "?test=test"`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Function" where return input parameter value without modification and use "publicPath" option', async () => { + const compiler = getCompiler('simple.js', { + publicPath: 'public_path/', + postTransformPublicPath: (p) => p, }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + }); - it('matches snapshot for prefixing with __webpack_public_path__', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Function" where append to input parameter value and use "publicPath" option', async () => { + const compiler = getCompiler('simple.js', { + publicPath: 'public_path/', + postTransformPublicPath: (p) => `${p} + "?test=test"`, }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - describe('`{Function}` value', () => { - it('matches snapshot for returned input parameter value without modification', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath(url) { - return `public_path/${url}`; - }, - postTransformPublicPath: (p) => p, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Function" and "publicPath" option as "Function"', async () => { + const compiler = getCompiler('simple.js', { + publicPath(url) { + return `public_path/${url}`; + }, + postTransformPublicPath: (p) => p, }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + }); - it('matches snapshot for appending to input parameter value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath(url) { - return `public_path/${url}`; - }, - postTransformPublicPath: (p) => `${p} + "?test=test"`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Function" where append to input parameter value and "publicPath" option as "Function"', async () => { + const compiler = getCompiler('simple.js', { + publicPath(url) { + return `public_path/${url}`; + }, + postTransformPublicPath: (p) => `${p} + "?test=test"`, }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + }); - it('matches snapshot for prefixing with string', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => `"path_prefix/" + ${p}`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "Function" where prepend path and "publicPath" option as "String"', async () => { + const compiler = getCompiler('simple.js', { + publicPath: 'public_path/', + postTransformPublicPath: (p) => `"path_prefix/" + ${p}`, }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); + }); - it('matches snapshot for prefixing with __webpack_public_path__', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`, - }, + it('should work with "Function" where prepend "__webpack_public_path__" and "publicPath" option as "String"', async () => { + const compiler = getCompiler( + 'simple.js', + { + publicPath: 'public_path/', + postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`, + }, + { + output: { + publicPath: 'http://code.com/', + path: path.resolve(__dirname, 'outputs'), + filename: '[name].bundle.js', + chunkFilename: '[name].chunk.js', }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); + } + ); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); }); diff --git a/test/publicPath-option.test.js b/test/publicPath-option.test.js index 6980fb2..1e4b787 100644 --- a/test/publicPath-option.test.js +++ b/test/publicPath-option.test.js @@ -1,129 +1,90 @@ -import webpack from './helpers/compiler'; - -describe('when applied with `publicPath` option', () => { - it('matches snapshot without value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); +import { + compile, + execute, + getCompiler, + normalizeErrors, + readAsset, +} from './helpers'; + +describe('"publicPath" option', () => { + it('should work without value', async () => { + const compiler = getCompiler('simple.js'); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "String" value', async () => { + const compiler = getCompiler('simple.js', { + publicPath: 'public_path/', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` value without trailing slash', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path', - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "String" value without trailing slash', async () => { + const compiler = getCompiler('simple.js', { + publicPath: 'public_path', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{String}` value as URL', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'https://cdn.com/', - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + it('should work with "String" value equal an URL', async () => { + const compiler = getCompiler('simple.js', { + publicPath: 'https://cdn.com/', + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); - it('matches snapshot for `{Function}` value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath(url) { - return `public_path/${url}`; - }, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for `{Function}` value and pass `resourcePath`', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath(url, resourcePath) { - expect(resourcePath).toMatch('file.png'); - - return `public_path/${url}`; - }, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); + it('should work with "Function" value and pass "url", "resourcePath" and "context" as arguments', async () => { + expect.assertions(6); - it('matches snapshot for `{Function}` value and pass `context`', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath(url, resourcePath, context) { - expect(context).toMatch('fixtures'); + const compiler = getCompiler('simple.js', { + publicPath(url, resourcePath, context) { + expect(url).toMatch('9c87cbf3ba33126ffd25ae7f2f6bbafb.png'); + expect(resourcePath).toMatch('file.png'); + expect(context).toMatch('fixtures'); - return `public_path/${url}`; - }, - }, + return `public_path/${url}`; }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); + }); + const stats = await compile(compiler); + + expect( + execute(readAsset('main.bundle.js', compiler, stats)) + ).toMatchSnapshot('result'); + expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( + 'warnings' + ); + expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); }); }); diff --git a/test/validate-options.test.js b/test/validate-options.test.js new file mode 100644 index 0000000..94bd17d --- /dev/null +++ b/test/validate-options.test.js @@ -0,0 +1,84 @@ +import { getCompiler, compile } from './helpers'; + +describe('validate options', () => { + const tests = { + name: { + success: ['[path][name].[ext]', () => '[path][name].[ext]'], + failure: [true], + }, + outputPath: { + success: ['assets', () => 'assets'], + failure: [true], + }, + publicPath: { + success: ['assets', () => 'assets'], + failure: [true], + }, + context: { + success: ['assets'], + failure: [true], + }, + emitFile: { + success: [true, false], + failure: ['true'], + }, + regExp: { + success: [/image\.png/, 'image.png'], + failure: [true], + }, + esModules: { + success: [true, false], + failure: ['true'], + }, + unknown: { + success: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }], + failure: [], + }, + }; + + function stringifyValue(value) { + if ( + Array.isArray(value) || + (value && typeof value === 'object' && value.constructor === Object) + ) { + return JSON.stringify(value); + } + + return value; + } + + async function createTestCase(key, value, type) { + it(`should ${ + type === 'success' ? 'successfully validate' : 'throw an error on' + } the "${key}" option with "${stringifyValue(value)}" value`, async () => { + const compiler = getCompiler('simple.js', { [key]: value }); + + let stats; + + try { + stats = await compile(compiler); + } finally { + if (type === 'success') { + expect(stats.hasErrors()).toBe(false); + } else if (type === 'failure') { + const { + compilation: { errors }, + } = stats; + + expect(errors).toHaveLength(1); + expect(() => { + throw new Error(errors[0].error.message); + }).toThrowErrorMatchingSnapshot(); + } + } + }); + } + + for (const [key, values] of Object.entries(tests)) { + for (const type of Object.keys(values)) { + for (const value of values[type]) { + createTestCase(key, value, type); + } + } + } +}); diff --git a/test/validation-options.test.js b/test/validation-options.test.js deleted file mode 100644 index 1d7b796..0000000 --- a/test/validation-options.test.js +++ /dev/null @@ -1,63 +0,0 @@ -import loader from '../src'; - -it('validate options', () => { - const validate = (options) => - loader.call( - Object.assign( - {}, - { - resourcePath: 'image.png', - query: options, - emitFile: () => {}, - } - ), - 'a { color: red; }' - ); - - expect(() => validate()).not.toThrow(); - - // The `file-loader` loader can be used as `fallback` loader and options can contain not only `file-loader` options - // so we use `additionalProperties: false` to avoid problems. - expect(() => validate({ limit: 8192 })).not.toThrow(); - - expect(() => validate({ name: '[path][name].[ext]' })).not.toThrow(); - expect(() => - validate({ - name: () => '[hash].[ext]', - }) - ).not.toThrow(); - expect(() => validate({ name: true })).toThrowErrorMatchingSnapshot(); - - expect(() => validate({ outputPath: 'assets' })).not.toThrow(); - expect(() => - validate({ - outputPath: () => 'assets', - }) - ).not.toThrow(); - expect(() => validate({ outputPath: true })).toThrowErrorMatchingSnapshot(); - - expect(() => validate({ publicPath: 'assets' })).not.toThrow(); - expect(() => - validate({ - publicPath: () => 'assets', - }) - ).not.toThrow(); - expect(() => validate({ publicPath: true })).toThrowErrorMatchingSnapshot(); - - expect(() => validate({ context: 'assets' })).not.toThrow(); - expect(() => validate({ context: true })).toThrowErrorMatchingSnapshot(); - - expect(() => validate({ emitFile: true })).not.toThrow(); - expect(() => validate({ emitFile: false })).not.toThrow(); - expect(() => validate({ emitFile: 'true' })).toThrowErrorMatchingSnapshot(); - - expect(() => validate({ regExp: /image\.png/ })).not.toThrow(); - expect(() => validate({ regExp: 'image\\.png' })).not.toThrow(); - expect(() => validate({ regExp: true })).toThrowErrorMatchingSnapshot(); - - expect(() => validate({ esModules: true })).not.toThrow(); - expect(() => validate({ esModules: false })).not.toThrow(); - expect(() => validate({ esModules: 'true' })).toThrowErrorMatchingSnapshot(); - - expect(() => validate({ unknown: 'unknown' })).not.toThrow(); -});