Skip to content

Commit

Permalink
test: improve (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Oct 7, 2020
1 parent 5fafdf8 commit bc0ca2c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 38 additions & 7 deletions test/TestCache.test.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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) => {
Expand All @@ -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);

Expand All @@ -73,6 +73,9 @@ describe('TestCache', () => {
mode: 'development',
context: directoryForCase,
cache: false,
output: {
path: outputPath,
},
});

await new Promise((resolve, reject) => {
Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -128,6 +136,9 @@ describe('TestCache', () => {
cache: {
type: 'memory',
},
output: {
path: outputPath,
},
});

await new Promise((resolve, reject) => {
Expand All @@ -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);

Expand All @@ -154,6 +166,9 @@ describe('TestCache', () => {
cache: {
type: 'memory',
},
output: {
path: outputPath,
},
});

await new Promise((resolve, reject) => {
Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -212,6 +235,9 @@ describe('TestCache', () => {
idleTimeout: 0,
idleTimeoutForInitialStore: 0,
},
output: {
path: outputPath,
},
});

await new Promise((resolve, reject) => {
Expand All @@ -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);

Expand All @@ -241,6 +268,9 @@ describe('TestCache', () => {
idleTimeout: 0,
idleTimeoutForInitialStore: 0,
},
output: {
path: outputPath,
},
});

await new Promise((resolve, reject) => {
Expand All @@ -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);

Expand Down

0 comments on commit bc0ca2c

Please sign in to comment.