From bc0ca2cc8e2c96c0cd492643e17b49633f6d9388 Mon Sep 17 00:00:00 2001 From: Alexander Krasnoyarov Date: Wed, 7 Oct 2020 15:16:12 +0300 Subject: [PATCH] test: improve (#601) --- package-lock.json | 6 +++--- test/TestCache.test.js | 45 +++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3b8df913..831f58eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16521,9 +16521,9 @@ }, "dependencies": { "acorn": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz", - "integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA==", + "version": "6.4.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.2.tgz", + "integrity": "sha512-XtGIhXwF8YM8bJhGxG5kXgjkEuNGLTkoYqVE+KMR+aspr4KGYmKYg7yUe3KghyQ9yheNwLnjmzh/7+gfDBmHCQ==", "dev": true }, "eslint-scope": { diff --git a/test/TestCache.test.js b/test/TestCache.test.js index 88efc0cc..76956b64 100644 --- a/test/TestCache.test.js +++ b/test/TestCache.test.js @@ -7,13 +7,6 @@ import path from 'path'; import webpack from 'webpack'; import del from 'del'; -const fileSystemCacheDirectory = path.resolve( - __dirname, - './outputs/cache/type-filesystem' -); - -del.sync(fileSystemCacheDirectory); - describe('TestCache', () => { afterEach(() => { jest.clearAllMocks(); @@ -43,12 +36,18 @@ describe('TestCache', () => { directoryForCase, 'webpack.config.js' )); + const outputPath = path.resolve(__dirname, 'js/cache-false'); + + await del([outputPath]); const compiler1 = webpack({ ...webpackConfig, mode: 'development', context: directoryForCase, cache: false, + output: { + path: outputPath, + }, }); await new Promise((resolve, reject) => { @@ -59,6 +58,7 @@ describe('TestCache', () => { return; } + expect(stats.compilation.emittedAssets.size).toBe(2); expect(stats.compilation.warnings).toHaveLength(0); expect(stats.compilation.errors).toHaveLength(0); @@ -73,6 +73,9 @@ describe('TestCache', () => { mode: 'development', context: directoryForCase, cache: false, + output: { + path: outputPath, + }, }); await new Promise((resolve, reject) => { @@ -83,6 +86,8 @@ describe('TestCache', () => { return; } + // Because webpack compare the source content before emitting + expect(stats.compilation.emittedAssets.size).toBe(0); expect(stats.compilation.warnings).toHaveLength(0); expect(stats.compilation.errors).toHaveLength(0); @@ -120,6 +125,9 @@ describe('TestCache', () => { directoryForCase, 'webpack.config.js' )); + const outputPath = path.resolve(__dirname, 'js/cache-memory'); + + await del([outputPath]); const compiler1 = webpack({ ...webpackConfig, @@ -128,6 +136,9 @@ describe('TestCache', () => { cache: { type: 'memory', }, + output: { + path: outputPath, + }, }); await new Promise((resolve, reject) => { @@ -138,6 +149,7 @@ describe('TestCache', () => { return; } + expect(stats.compilation.emittedAssets.size).toBe(2); expect(stats.compilation.warnings).toHaveLength(0); expect(stats.compilation.errors).toHaveLength(0); @@ -154,6 +166,9 @@ describe('TestCache', () => { cache: { type: 'memory', }, + output: { + path: outputPath, + }, }); await new Promise((resolve, reject) => { @@ -164,6 +179,7 @@ describe('TestCache', () => { return; } + expect(stats.compilation.emittedAssets.size).toBe(0); expect(stats.compilation.warnings).toHaveLength(0); expect(stats.compilation.errors).toHaveLength(0); @@ -201,6 +217,13 @@ describe('TestCache', () => { directoryForCase, 'webpack.config.js' )); + const outputPath = path.resolve(__dirname, 'js/cache-filesystem'); + const fileSystemCacheDirectory = path.resolve( + __dirname, + './js/.cache/type-filesystem' + ); + + await del([outputPath, fileSystemCacheDirectory]); const compiler1 = webpack({ ...webpackConfig, @@ -212,6 +235,9 @@ describe('TestCache', () => { idleTimeout: 0, idleTimeoutForInitialStore: 0, }, + output: { + path: outputPath, + }, }); await new Promise((resolve, reject) => { @@ -222,6 +248,7 @@ describe('TestCache', () => { return; } + expect(stats.compilation.emittedAssets.size).toBe(2); expect(stats.compilation.warnings).toHaveLength(0); expect(stats.compilation.errors).toHaveLength(0); @@ -241,6 +268,9 @@ describe('TestCache', () => { idleTimeout: 0, idleTimeoutForInitialStore: 0, }, + output: { + path: outputPath, + }, }); await new Promise((resolve, reject) => { @@ -251,6 +281,7 @@ describe('TestCache', () => { return; } + expect(stats.compilation.emittedAssets.size).toBe(0); expect(stats.compilation.warnings).toHaveLength(0); expect(stats.compilation.errors).toHaveLength(0);