| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9b0db8f commit fda4d2e
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + import normalizeErrors from './normalizeErrors'; | ||
| 2 | + | ||
| 3 | + export default (stats) => { | ||
| 4 | + return normalizeErrors(stats.compilation.errors); | ||
| 5 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + import normalizeErrors from './normalizeErrors'; | ||
| 2 | + | ||
| 3 | + export default (stats) => { | ||
| 4 | + return normalizeErrors(stats.compilation.warnings); | ||
| 5 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,19 @@ | |||
| 1 | 1 | import compile from './compile'; | |
| 2 | + import execute from './execute'; | ||
| 2 | 3 | import getCompiler from './getCompiler'; | |
| 4 | + import getErrors from './getErrors'; | ||
| 5 | + import getWarnings from './getWarnings'; | ||
| 3 | 6 | import normalizeErrors from './normalizeErrors'; | |
| 4 | 7 | import readAsset from './readAsset'; | |
| 8 | + import readsAssets from './readAssets'; | ||
| 5 | 9 | ||
| 6 | - export { compile, getCompiler, normalizeErrors, readAsset }; | ||
| 10 | + export { | ||
| 11 | + compile, | ||
| 12 | + execute, | ||
| 13 | + getCompiler, | ||
| 14 | + getErrors, | ||
| 15 | + getWarnings, | ||
| 16 | + normalizeErrors, | ||
| 17 | + readAsset, | ||
| 18 | + readsAssets, | ||
| 19 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,10 +3,18 @@ import path from 'path'; | |||
| 3 | 3 | export default (asset, compiler, stats) => { | |
| 4 | 4 | const usedFs = compiler.outputFileSystem; | |
| 5 | 5 | const outputPath = stats.compilation.outputOptions.path; | |
| 6 | + | ||
| 6 | 7 | let data = ''; | |
| 8 | + let targetFile = asset; | ||
| 9 | + | ||
| 10 | + const queryStringIdx = targetFile.indexOf('?'); | ||
| 11 | + | ||
| 12 | + if (queryStringIdx >= 0) { | ||
| 13 | + targetFile = targetFile.substr(0, queryStringIdx); | ||
| 14 | + } | ||
| 7 | 15 | ||
| 8 | 16 | try { | |
| 9 | - data = usedFs.readFileSync(path.join(outputPath, asset)).toString(); | ||
| 17 | + data = usedFs.readFileSync(path.join(outputPath, targetFile)).toString(); | ||
| 10 | 18 | } catch (error) { | |
| 11 | 19 | data = error.toString(); | |
| 12 | 20 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + import readAsset from './readAsset'; | ||
| 2 | + | ||
| 3 | + export default function readAssets(compiler, stats) { | ||
| 4 | + const assets = {}; | ||
| 5 | + | ||
| 6 | + Object.keys(stats.compilation.assets).forEach((asset) => { | ||
| 7 | + assets[asset] = readAsset(asset, compiler, stats); | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + return assets; | ||
| 11 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,8 @@ import { | |||
| 2 | 2 | compile, | |
| 3 | 3 | execute, | |
| 4 | 4 | getCompiler, | |
| 5 | - normalizeErrors, | ||
| 5 | + getErrors, | ||
| 6 | + getWarnings, | ||
| 6 | 7 | readAsset, | |
| 7 | 8 | } from './helpers'; | |
| 8 | 9 | ||
@@ -14,9 +15,7 @@ describe('loader', () => { | |||
| 14 | 15 | expect( | |
| 15 | 16 | execute(readAsset('main.bundle.js', compiler, stats)) | |
| 16 | 17 | ).toMatchSnapshot('result'); | |
| 17 | - expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( | ||
| 18 | - 'warnings' | ||
| 19 | - ); | ||
| 20 | - expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); | ||
| 18 | + expect(getErrors(stats)).toMatchSnapshot('errors'); | ||
| 19 | + expect(getWarnings(stats)).toMatchSnapshot('warnings'); | ||
| 21 | 20 | }); | |
| 22 | 21 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,11 @@ | |||
| 1 | - import { compile, getCompiler, normalizeErrors, readAsset } from './helpers'; | ||
| 1 | + import { | ||
| 2 | + compile, | ||
| 3 | + execute, | ||
| 4 | + getCompiler, | ||
| 5 | + getErrors, | ||
| 6 | + getWarnings, | ||
| 7 | + readAsset, | ||
| 8 | + } from './helpers'; | ||
| 2 | 9 | ||
| 3 | 10 | describe('"name" option', () => { | |
| 4 | 11 | it('should work with "Boolean" value equal "true"', async () => { | |
@@ -7,12 +14,10 @@ describe('"name" option', () => { | |||
| 7 | 14 | }); | |
| 8 | 15 | const stats = await compile(compiler); | |
| 9 | 16 | ||
| 10 | - expect(readAsset('main.bundle.js', compiler, stats)).toMatchSnapshot( | ||
| 11 | - 'result' | ||
| 12 | - ); | ||
| 13 | - expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot( | ||
| 14 | - 'warnings' | ||
| 15 | - ); | ||
| 16 | - expect(normalizeErrors(stats.compilation.errors)).toMatchSnapshot('errors'); | ||
| 17 | + expect( | ||
| 18 | + execute(readAsset('main.bundle.js', compiler, stats)) | ||
| 19 | + ).toMatchSnapshot('result'); | ||
| 20 | + expect(getErrors(stats)).toMatchSnapshot('errors'); | ||
| 21 | + expect(getWarnings(stats)).toMatchSnapshot('warnings'); | ||
| 17 | 22 | }); | |
| 18 | 23 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,26 +23,48 @@ describe('validate options', () => { | |||
| 23 | 23 | it(`should ${ | |
| 24 | 24 | type === 'success' ? 'successfully validate' : 'throw an error on' | |
| 25 | 25 | } the "${key}" option with "${stringifyValue(value)}" value`, async () => { | |
| 26 | - const compiler = getCompiler('simple.js', { [key]: value }); | ||
| 27 | - | ||
| 28 | - let stats; | ||
| 29 | - | ||
| 30 | - try { | ||
| 31 | - stats = await compile(compiler); | ||
| 32 | - } finally { | ||
| 33 | - if (type === 'success') { | ||
| 34 | - expect(stats.hasErrors()).toBe(false); | ||
| 35 | - } else if (type === 'failure') { | ||
| 36 | - const { | ||
| 37 | - compilation: { errors }, | ||
| 38 | - } = stats; | ||
| 39 | - | ||
| 40 | - expect(errors).toHaveLength(1); | ||
| 41 | - expect(() => { | ||
| 42 | - throw new Error(errors[0].error.message); | ||
| 43 | - }).toThrowErrorMatchingSnapshot(); | ||
| 44 | - } | ||
| 45 | - } | ||
| 26 | + // For loaders | ||
| 27 | + // const compiler = getCompiler('simple.js', { [key]: value }); | ||
| 28 | + // | ||
| 29 | + // let stats; | ||
| 30 | + // | ||
| 31 | + // try { | ||
| 32 | + // stats = await compile(compiler); | ||
| 33 | + // } finally { | ||
| 34 | + // if (type === 'success') { | ||
| 35 | + // expect(stats.hasErrors()).toBe(false); | ||
| 36 | + // } else if (type === 'failure') { | ||
| 37 | + // const { | ||
| 38 | + // compilation: { errors }, | ||
| 39 | + // } = stats; | ||
| 40 | + // | ||
| 41 | + // expect(errors).toHaveLength(1); | ||
| 42 | + // expect(() => { | ||
| 43 | + // throw new Error(errors[0].error.message); | ||
| 44 | + // }).toThrowErrorMatchingSnapshot(); | ||
| 45 | + // } | ||
| 46 | + // } | ||
| 47 | + // For plugins | ||
| 48 | + // let error; | ||
| 49 | + // | ||
| 50 | + // try { | ||
| 51 | + // // eslint-disable-next-line no-new | ||
| 52 | + // new Plugin({ [key]: value }); | ||
| 53 | + // } catch (errorFromPlugin) { | ||
| 54 | + // if (errorFromPlugin.name !== 'ValidationError') { | ||
| 55 | + // throw errorFromPlugin; | ||
| 56 | + // } | ||
| 57 | + // | ||
| 58 | + // error = errorFromPlugin; | ||
| 59 | + // } finally { | ||
| 60 | + // if (type === 'success') { | ||
| 61 | + // expect(error).toBeUndefined(); | ||
| 62 | + // } else if (type === 'failure') { | ||
| 63 | + // expect(() => { | ||
| 64 | + // throw error; | ||
| 65 | + // }).toThrowErrorMatchingSnapshot(); | ||
| 66 | + // } | ||
| 67 | + // } | ||
| 46 | 68 | }); | |
| 47 | 69 | } | |
| 48 | 70 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments