Skip to content

Commit

Permalink
tests: add tests for cache related core flags
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 16, 2020
1 parent 464cc7b commit 277b765
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jest.config.js
@@ -1,5 +1,9 @@
const { version } = require('webpack');

const ignorePattern = version.startsWith('5') ? ['<rootDir>/node_modules/'] : ['<rootDir>/node_modules/', '<rootDir>/test/core-flags'];

module.exports = {
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
testPathIgnorePatterns: ignorePattern,
// transformIgnorePatterns: ['<rootDir>.*(node_modules)(?!.*webpack-cli.*).*$'],
testEnvironment: 'node',
collectCoverage: true,
Expand Down
75 changes: 75 additions & 0 deletions test/core-flags/cache-flags.test.js
@@ -0,0 +1,75 @@
'use strict';

const { run } = require('../utils/test-utils');

describe('cahche related flags from core', () => {
it('should be successful with --cache ', () => {
const { stderr, stdout } = run(__dirname, ['--cache']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`type: 'memory'`);
});

it('should set cache.type', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`type: 'filesystem'`);
});

it('should set cache.cacheDirectory with --cache-cache-directory', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-directory', '/test-cache-path']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`cacheDirectory: '/test-cache-path'`);
});

it('should set cache.cacheLocation with --cache-cache-locations', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-location', '/test-locate-cache']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`cacheLocation: '/test-locate-cache'`);
});

it('should set cache.hashAlgorithm with --cache-hash-algorithm', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-hash-algorithm', 'sha256']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`hashAlgorithm: 'sha256'`);
});

it('should set cache.managedPaths with --cache-managed-paths', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'memory', '--cache-managed-paths', '/test-manage-path']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`managedPaths: [ '/test-manage-path' ]`);
});

it('should reset cache.managedPaths with --cache-managed-paths-reset', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-managed-paths-reset']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`managedPaths: []`);
});

it('should set cache.name with --cache-name', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-name', 'cli-test']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`name: 'cli-test'`);
});

it('should set cache.store with --cache-store', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-store', 'pack']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`store: 'pack'`);
});

it('should set cache.version with --cache-version', () => {
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-version', '1.1.3']);

expect(stderr).toBeFalsy();
expect(stdout).toContain(`version: '1.1.3'`);
});
});
1 change: 1 addition & 0 deletions test/core-flags/main.js
@@ -0,0 +1 @@
console.log('core-flags tests');
7 changes: 7 additions & 0 deletions test/core-flags/webpack.config.js
@@ -0,0 +1,7 @@
const WebpackCLITestPlugin = require('../utils/webpack-cli-test-plugin');

module.exports = {
entry: './main.js',
mode: 'development',
plugins: [new WebpackCLITestPlugin()],
};

0 comments on commit 277b765

Please sign in to comment.