|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const { run } = require('../utils/test-utils'); |
4 |
| -const { existsSync } = require('fs'); |
| 3 | +const { run, isWindows } = require('../utils/test-utils'); |
| 4 | +const { existsSync, writeFileSync, unlinkSync } = require('fs'); |
5 | 5 | const { resolve } = require('path');
|
6 | 6 |
|
7 | 7 | describe('cache related flags from core', () => {
|
8 | 8 | it('should be successful with --cache ', () => {
|
9 | 9 | const { stderr, stdout } = run(__dirname, ['--cache']);
|
10 |
| - |
11 | 10 | expect(stderr).toBeFalsy();
|
12 | 11 | expect(stdout).toContain(`type: 'memory'`);
|
13 | 12 | });
|
@@ -69,4 +68,79 @@ describe('cache related flags from core', () => {
|
69 | 68 | expect(stderr).toBeFalsy();
|
70 | 69 | expect(stdout).toContain(`version: '1.1.3'`);
|
71 | 70 | });
|
| 71 | + |
| 72 | + it('should assign cache build dependencies correctly when cache type is filesystem', () => { |
| 73 | + // TODO: Fix on windows |
| 74 | + if (isWindows) return; |
| 75 | + const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.config.js']); |
| 76 | + expect(stderr).toBeFalsy(); |
| 77 | + expect(stdout).toContain('buildDependencies'); |
| 78 | + expect(stdout).toContain("config: [ './webpack.config.js' ]"); |
| 79 | + expect(stdout).not.toContain('[cached] 1 module'); |
| 80 | + // Run again to check for cache |
| 81 | + const newRun = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.config.js']); |
| 82 | + expect(newRun.stdout).toContain('[cached] 1 module'); |
| 83 | + expect(newRun.stderr).toBeFalsy(); |
| 84 | + expect(newRun.exitCode).toEqual(0); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should assign cache build dependencies correctly when cache type is filesystem in config', () => { |
| 88 | + // TODO: Fix on windows |
| 89 | + if (isWindows) return; |
| 90 | + const { stderr, stdout } = run(__dirname, ['-c', './webpack.cache.config.js']); |
| 91 | + expect(stderr).toBeFalsy(); |
| 92 | + expect(stdout).toContain('buildDependencies'); |
| 93 | + expect(stdout).toContain("config: [ './webpack.cache.config.js' ]"); |
| 94 | + expect(stdout).toContain("type: 'filesystem'"); |
| 95 | + // Run again to check for cache |
| 96 | + const newRun = run(__dirname, ['-c', './webpack.cache.config.js']); |
| 97 | + expect(newRun.stdout).toContain('[cached] 1 module'); |
| 98 | + expect(newRun.stderr).toBeFalsy(); |
| 99 | + expect(newRun.exitCode).toEqual(0); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should assign cache build dependencies with multiple configs', () => { |
| 103 | + // TODO: Fix on windows |
| 104 | + if (isWindows) return; |
| 105 | + const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js']); |
| 106 | + expect(stderr).toBeFalsy(); |
| 107 | + expect(stdout).toContain('buildDependencies'); |
| 108 | + expect(stdout).toContain("config: [ './webpack.cache.config.js', './webpack.config.js' ]"); |
| 109 | + expect(stdout).toContain("type: 'filesystem'"); |
| 110 | + expect(exitCode).toEqual(0); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should assign cache build dependencies with merged configs', () => { |
| 114 | + // TODO: Fix on windows |
| 115 | + if (isWindows) return; |
| 116 | + const { stderr, stdout, exitCode } = run(__dirname, ['-c', './webpack.cache.config.js', '-c', './webpack.config.js', '--merge']); |
| 117 | + expect(stderr).toBeFalsy(); |
| 118 | + expect(stdout).toContain('buildDependencies'); |
| 119 | + expect(stdout).toContain("config: [ './webpack.cache.config.js', './webpack.config.js' ]"); |
| 120 | + expect(stdout).toContain("type: 'filesystem'"); |
| 121 | + expect(exitCode).toEqual(0); |
| 122 | + }); |
| 123 | + |
| 124 | + it('should invalidate cache when config changes', () => { |
| 125 | + // TODO: Fix on windows |
| 126 | + if (isWindows) return; |
| 127 | + // Creating a temporary webpack config |
| 128 | + writeFileSync(resolve(__dirname, './webpack.test.config.js'), 'module.exports = {mode: "development"}'); |
| 129 | + const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); |
| 130 | + expect(stderr).toBeFalsy(); |
| 131 | + // modules should not be cached on first run |
| 132 | + expect(stdout).not.toContain('[cached] 1 module'); |
| 133 | + |
| 134 | + // Running again should use the cache |
| 135 | + const newRun = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); |
| 136 | + expect(newRun.stdout).toContain('[cached] 1 module'); |
| 137 | + |
| 138 | + // Change config to invalidate cache |
| 139 | + writeFileSync(resolve(__dirname, './webpack.test.config.js'), 'module.exports = {mode: "production"}'); |
| 140 | + |
| 141 | + const newRun2 = run(__dirname, ['--cache-type', 'filesystem', '-c', './webpack.test.config.js']); |
| 142 | + unlinkSync(resolve(__dirname, './webpack.test.config.js')); |
| 143 | + expect(newRun2).not.toContain('[cached] 1 module'); |
| 144 | + expect(newRun2.exitCode).toEqual(0); |
| 145 | + }); |
72 | 146 | });
|
0 commit comments