diff --git a/src/cli/telemetry/test/telemetry.spec.ts b/src/cli/telemetry/test/telemetry.spec.ts
index 8af188bdc94..9cf24ac2939 100644
--- a/src/cli/telemetry/test/telemetry.spec.ts
+++ b/src/cli/telemetry/test/telemetry.spec.ts
@@ -14,9 +14,11 @@ describe('telemetryBuildFinishedAction', () => {
beforeEach(() => {
sys = createSystem();
- config = mockValidatedConfig(sys);
- config.outputTargets = [];
- config.flags.args = [];
+ config = mockValidatedConfig({
+ flags: createConfigFlags({ task: 'build' }),
+ outputTargets: [],
+ sys,
+ });
});
it('issues a network request when complete', async () => {
@@ -45,9 +47,11 @@ describe('telemetryAction', () => {
beforeEach(() => {
sys = createSystem();
- config = mockValidatedConfig(sys);
- config.outputTargets = [];
- config.flags.args = [];
+ config = mockValidatedConfig({
+ flags: createConfigFlags({ task: 'build' }),
+ outputTargets: [],
+ sys,
+ });
});
it('issues a network request when no async function is passed', async () => {
diff --git a/src/cli/test/run.spec.ts b/src/cli/test/run.spec.ts
index 0655b84ca81..42ffe501368 100644
--- a/src/cli/test/run.spec.ts
+++ b/src/cli/test/run.spec.ts
@@ -1,6 +1,11 @@
import type * as d from '../../declarations';
import * as coreCompiler from '@stencil/core/compiler';
-import { mockCompilerSystem, mockConfig, mockLogger as createMockLogger } from '@stencil/core/testing';
+import {
+ mockCompilerSystem,
+ mockConfig,
+ mockLogger as createMockLogger,
+ mockValidatedConfig,
+} from '@stencil/core/testing';
import * as ParseFlags from '../parse-flags';
import { run, runTask } from '../run';
import * as BuildTask from '../task-build';
@@ -132,11 +137,9 @@ describe('run', () => {
sys = mockCompilerSystem();
sys.exit = jest.fn();
- unvalidatedConfig = mockConfig(sys);
- unvalidatedConfig.outputTargets = null;
+ unvalidatedConfig = mockConfig({ outputTargets: null, sys });
- validatedConfig = mockConfig(sys);
- validatedConfig.outputTargets = [];
+ validatedConfig = mockValidatedConfig({ sys });
taskBuildSpy = jest.spyOn(BuildTask, 'taskBuild');
taskBuildSpy.mockResolvedValue();
@@ -256,8 +259,7 @@ describe('run', () => {
});
it('defaults to the provided task if no flags exist on the provided config', async () => {
- unvalidatedConfig = mockConfig(sys);
- unvalidatedConfig.flags = undefined;
+ unvalidatedConfig = mockConfig({ flags: undefined, sys });
await runTask(coreCompiler, unvalidatedConfig, 'help', sys);
diff --git a/src/cli/test/task-generate.spec.ts b/src/cli/test/task-generate.spec.ts
index b21002ed0af..e6c522d4676 100644
--- a/src/cli/test/task-generate.spec.ts
+++ b/src/cli/test/task-generate.spec.ts
@@ -5,6 +5,7 @@ import * as utils from '../../utils/validation';
import * as coreCompiler from '@stencil/core/compiler';
import { CoreCompiler } from '../load-compiler';
+import { createConfigFlags } from '../config-flags';
const promptMock = jest.fn().mockResolvedValue('my-component');
@@ -14,13 +15,15 @@ jest.mock('prompts', () => ({
const setup = async () => {
const sys = mockCompilerSystem();
- const config: d.ValidatedConfig = mockValidatedConfig(sys);
- config.configPath = '/testing-path';
- config.srcDir = '/src';
+ const config: d.ValidatedConfig = mockValidatedConfig({
+ configPath: '/testing-path',
+ flags: createConfigFlags({ task: 'generate' }),
+ srcDir: '/src',
+ sys,
+ });
// set up some mocks / spies
config.sys.exit = jest.fn();
- config.flags.unknownArgs = [];
const errorSpy = jest.spyOn(config.logger, 'error');
const validateTagSpy = jest.spyOn(utils, 'validateComponentTag').mockReturnValue(undefined);
diff --git a/src/compiler/output-targets/test/custom-elements-types.spec.ts b/src/compiler/output-targets/test/custom-elements-types.spec.ts
index 2cf3a1fb951..b6c15c7cd71 100644
--- a/src/compiler/output-targets/test/custom-elements-types.spec.ts
+++ b/src/compiler/output-targets/test/custom-elements-types.spec.ts
@@ -15,18 +15,21 @@ import { join, relative } from 'path';
const setup = () => {
const sys = mockCompilerSystem();
- const config: d.ValidatedConfig = mockValidatedConfig(sys);
+ const config: d.ValidatedConfig = mockValidatedConfig({
+ configPath: '/testing-path',
+ buildAppCore: true,
+ buildEs5: true,
+ namespace: 'TestApp',
+ outputTargets: [{ type: DIST_CUSTOM_ELEMENTS, dir: 'my-best-dir' }],
+ srcDir: '/src',
+ sys,
+ });
const compilerCtx = mockCompilerCtx(config);
const buildCtx = mockBuildCtx(config, compilerCtx);
+
const root = config.rootDir;
- config.configPath = '/testing-path';
- config.srcDir = '/src';
- config.buildAppCore = true;
config.rootDir = path.join(root, 'User', 'testing', '/');
- config.namespace = 'TestApp';
- config.buildEs5 = true;
config.globalScript = path.join(root, 'User', 'testing', 'src', 'global.ts');
- config.outputTargets = [{ type: DIST_CUSTOM_ELEMENTS, dir: 'my-best-dir' }];
const bundleCustomElementsSpy = jest.spyOn(outputCustomElementsMod, 'bundleCustomElements');
diff --git a/src/compiler/output-targets/test/output-targets-dist-custom-elements.spec.ts b/src/compiler/output-targets/test/output-targets-dist-custom-elements.spec.ts
index 5e0a0881043..0f4f8353b19 100644
--- a/src/compiler/output-targets/test/output-targets-dist-custom-elements.spec.ts
+++ b/src/compiler/output-targets/test/output-targets-dist-custom-elements.spec.ts
@@ -22,18 +22,21 @@ import { DIST_CUSTOM_ELEMENTS, DIST_CUSTOM_ELEMENTS_BUNDLE } from '../output-uti
const setup = () => {
const sys = mockCompilerSystem();
- const config: d.ValidatedConfig = mockValidatedConfig(sys);
+ const config: d.ValidatedConfig = mockValidatedConfig({
+ buildAppCore: true,
+ buildEs5: true,
+ configPath: '/testing-path',
+ namespace: 'TestApp',
+ outputTargets: [{ type: DIST_CUSTOM_ELEMENTS }],
+ srcDir: '/src',
+ sys,
+ });
const compilerCtx = mockCompilerCtx(config);
const buildCtx = mockBuildCtx(config, compilerCtx);
+
const root = config.rootDir;
- config.configPath = '/testing-path';
- config.srcDir = '/src';
- config.buildAppCore = true;
config.rootDir = path.join(root, 'User', 'testing', '/');
- config.namespace = 'TestApp';
- config.buildEs5 = true;
config.globalScript = path.join(root, 'User', 'testing', 'src', 'global.ts');
- config.outputTargets = [{ type: DIST_CUSTOM_ELEMENTS }];
const bundleCustomElementsSpy = jest.spyOn(outputCustomElementsMod, 'bundleCustomElements');
diff --git a/src/compiler/output-targets/test/output-targets-dist.spec.ts b/src/compiler/output-targets/test/output-targets-dist.spec.ts
index 2f1716d27fa..d38058b64e0 100644
--- a/src/compiler/output-targets/test/output-targets-dist.spec.ts
+++ b/src/compiler/output-targets/test/output-targets-dist.spec.ts
@@ -11,13 +11,14 @@ describe.skip('outputTarget, dist', () => {
const root = path.resolve('/');
it('default dist files', async () => {
- config = mockConfig();
- config.buildAppCore = true;
- config.rootDir = path.join(root, 'User', 'testing', '/');
- config.namespace = 'TestApp';
- config.buildEs5 = true;
- config.globalScript = path.join(root, 'User', 'testing', 'src', 'global.ts');
- config.outputTargets = [{ type: 'dist' }];
+ config = mockConfig({
+ buildAppCore: true,
+ buildEs5: true,
+ globalScript: path.join(root, 'User', 'testing', 'src', 'global.ts'),
+ namespace: 'TestApp',
+ outputTargets: [{ type: 'dist' }],
+ rootDir: path.join(root, 'User', 'testing', '/'),
+ });
compiler = new Compiler(config);
diff --git a/src/compiler/output-targets/test/output-targets-www-dist.spec.ts b/src/compiler/output-targets/test/output-targets-www-dist.spec.ts
index 6f778a72247..85dc79d7512 100644
--- a/src/compiler/output-targets/test/output-targets-www-dist.spec.ts
+++ b/src/compiler/output-targets/test/output-targets-www-dist.spec.ts
@@ -12,29 +12,30 @@ describe.skip('outputTarget, www / dist / docs', () => {
const root = path.resolve('/');
it('dist, www and readme files w/ custom paths', async () => {
- config = mockConfig();
- config.flags.docs = true;
- config.buildAppCore = true;
- config.rootDir = path.join(root, 'User', 'testing', '/');
- config.namespace = 'TestApp';
- config.outputTargets = [
- {
- type: 'www',
- dir: 'custom-www',
- buildDir: 'www-build',
- indexHtml: 'custom-index.htm',
- } as any as d.OutputTargetDist,
- {
- type: 'dist',
- dir: 'custom-dist',
- buildDir: 'dist-build',
- collectionDir: 'dist-collection',
- typesDir: 'custom-types',
- },
- {
- type: 'docs',
- } as d.OutputTargetDocsReadme,
- ];
+ config = mockConfig({
+ buildAppCore: true,
+ flags: { docs: true },
+ namespace: 'TestApp',
+ outputTargets: [
+ {
+ type: 'www',
+ dir: 'custom-www',
+ buildDir: 'www-build',
+ indexHtml: 'custom-index.htm',
+ } as any as d.OutputTargetDist,
+ {
+ type: 'dist',
+ dir: 'custom-dist',
+ buildDir: 'dist-build',
+ collectionDir: 'dist-collection',
+ typesDir: 'custom-types',
+ },
+ {
+ type: 'docs',
+ } as d.OutputTargetDocsReadme,
+ ],
+ rootDir: path.join(root, 'User', 'testing', '/'),
+ });
compiler = new Compiler(config);
diff --git a/src/compiler/output-targets/test/output-targets-www.spec.ts b/src/compiler/output-targets/test/output-targets-www.spec.ts
index 66f81a77f0c..cfd2a0d93c0 100644
--- a/src/compiler/output-targets/test/output-targets-www.spec.ts
+++ b/src/compiler/output-targets/test/output-targets-www.spec.ts
@@ -11,10 +11,11 @@ describe.skip('outputTarget, www', () => {
const root = path.resolve('/');
it('default www files', async () => {
- config = mockConfig();
- config.namespace = 'App';
- config.buildAppCore = true;
- config.rootDir = path.join(root, 'User', 'testing', '/');
+ config = mockConfig({
+ buildAppCore: true,
+ namespace: 'App',
+ rootDir: path.join(root, 'User', 'testing', '/'),
+ });
compiler = new Compiler(config);
diff --git a/src/compiler/service-worker/test/service-worker-util.spec.ts b/src/compiler/service-worker/test/service-worker-util.spec.ts
index 77903ea5a6c..27a726d6229 100644
--- a/src/compiler/service-worker/test/service-worker-util.spec.ts
+++ b/src/compiler/service-worker/test/service-worker-util.spec.ts
@@ -8,14 +8,15 @@ describe('generateServiceWorkerUrl', () => {
let outputTarget: d.OutputTargetWww;
it('sw url w/ baseUrl', () => {
- userConfig = mockConfig();
- userConfig.devMode = false;
- userConfig.outputTargets = [
- {
- type: 'www',
- baseUrl: '/docs',
- } as d.OutputTargetWww,
- ];
+ userConfig = mockConfig({
+ devMode: false,
+ outputTargets: [
+ {
+ type: 'www',
+ baseUrl: '/docs',
+ } as d.OutputTargetWww,
+ ],
+ });
const { config } = validateConfig(userConfig, mockLoadConfigInit());
outputTarget = config.outputTargets[0] as d.OutputTargetWww;
const swUrl = generateServiceWorkerUrl(outputTarget, outputTarget.serviceWorker as d.ServiceWorkerConfig);
@@ -23,8 +24,7 @@ describe('generateServiceWorkerUrl', () => {
});
it('default sw url', () => {
- userConfig = mockConfig();
- userConfig.devMode = false;
+ userConfig = mockConfig({ devMode: false });
const { config } = validateConfig(userConfig, mockLoadConfigInit());
outputTarget = config.outputTargets[0] as d.OutputTargetWww;
const swUrl = generateServiceWorkerUrl(outputTarget, outputTarget.serviceWorker as d.ServiceWorkerConfig);
diff --git a/src/compiler/service-worker/test/service-worker.spec.ts b/src/compiler/service-worker/test/service-worker.spec.ts
index 60a0c8dab2d..4debd729fb0 100644
--- a/src/compiler/service-worker/test/service-worker.spec.ts
+++ b/src/compiler/service-worker/test/service-worker.spec.ts
@@ -13,17 +13,18 @@ describe.skip('service worker', () => {
const root = path.resolve('/');
it('dev service worker', async () => {
- config = mockConfig();
- config.devMode = true;
- config.outputTargets = [
- {
- type: 'www',
- serviceWorker: {
- swSrc: path.join('src', 'sw.js'),
- globPatterns: ['**/*.{html,js,css,json,ico,png}'],
- },
- } as d.OutputTargetWww,
- ];
+ config = mockConfig({
+ devMode: true,
+ outputTargets: [
+ {
+ type: 'www',
+ serviceWorker: {
+ swSrc: path.join('src', 'sw.js'),
+ globPatterns: ['**/*.{html,js,css,json,ico,png}'],
+ },
+ } as d.OutputTargetWww,
+ ],
+ });
compiler = new Compiler(config);
await compiler.fs.writeFile(path.join(root, 'www', 'script.js'), `/**/`);
diff --git a/src/compiler/style/test/optimize-css.spec.ts b/src/compiler/style/test/optimize-css.spec.ts
index 2173af31cd6..e05ead98d03 100644
--- a/src/compiler/style/test/optimize-css.spec.ts
+++ b/src/compiler/style/test/optimize-css.spec.ts
@@ -14,15 +14,13 @@ describe('optimizeCss', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
beforeEach(() => {
- config = mockConfig();
- config.maxConcurrentWorkers = 0;
+ config = mockConfig({ maxConcurrentWorkers: 0, minifyCss: true });
compilerCtx = mockCompilerCtx(config);
diagnostics = [];
});
it('handles error', async () => {
const filePath = path.join(os.tmpdir(), 'my.css');
- config.minifyCss = true;
const styleText = `/* css */ body color: #ff0000; }`;
await optimizeCss(config, compilerCtx, diagnostics, styleText, filePath);
@@ -30,7 +28,6 @@ describe('optimizeCss', () => {
});
it('discard-comments', async () => {
- config.minifyCss = true;
const styleText = `/* css */ body { color: #ff0000; }`;
const output = await optimizeCss(config, compilerCtx, diagnostics, styleText, null);
@@ -40,7 +37,6 @@ describe('optimizeCss', () => {
it('minify-gradients', async () => {
config.autoprefixCss = false;
- config.minifyCss = true;
const styleText = `
h1 {
background: linear-gradient(to bottom, #ffe500 0%, #ffe500 50%, #121 50%, #121 100%);
@@ -53,7 +49,6 @@ describe('optimizeCss', () => {
});
it('reduce-initial', async () => {
- config.minifyCss = true;
const styleText = `
h1 {
min-width: initial;
@@ -66,7 +61,6 @@ describe('optimizeCss', () => {
});
it('normalize-display-values', async () => {
- config.minifyCss = true;
const styleText = `
h1 {
display: inline flow-root;
@@ -80,7 +74,6 @@ describe('optimizeCss', () => {
it('reduce-transforms', async () => {
config.autoprefixCss = false;
- config.minifyCss = true;
const styleText = `
h1 {
transform: rotate3d(0, 0, 1, 20deg);
@@ -93,7 +86,6 @@ describe('optimizeCss', () => {
});
it('colormin', async () => {
- config.minifyCss = true;
const styleText = `body { color: #ff0000; }`;
const output = await optimizeCss(config, compilerCtx, diagnostics, styleText, null);
@@ -102,7 +94,6 @@ describe('optimizeCss', () => {
});
it('convert-values', async () => {
- config.minifyCss = true;
const styleText = `
h1 {
width: 0em;
@@ -115,7 +106,6 @@ describe('optimizeCss', () => {
});
it('ordered-values', async () => {
- config.minifyCss = true;
const styleText = `
h1 {
border: red solid .5em;
@@ -128,7 +118,6 @@ describe('optimizeCss', () => {
});
it('minify-selectors', async () => {
- config.minifyCss = true;
const styleText = `
h1 + p, h2, h3, h2{color:red}
`;
@@ -139,7 +128,6 @@ describe('optimizeCss', () => {
});
it('minify-params', async () => {
- config.minifyCss = true;
const styleText = `
@media only screen and ( min-width: 400px, min-height: 500px ) {
h2 {
@@ -154,7 +142,6 @@ describe('optimizeCss', () => {
});
it('normalize-string', async () => {
- config.minifyCss = true;
const styleText = `
p:after {
content: '\\'string\\' is intact';
@@ -167,7 +154,6 @@ describe('optimizeCss', () => {
});
it('minify-font-values', async () => {
- config.minifyCss = true;
const styleText = `
p {
font-family: "Helvetica Neue", Arial, sans-serif, Helvetica;
@@ -181,7 +167,6 @@ describe('optimizeCss', () => {
});
it('normalize-repeat-style', async () => {
- config.minifyCss = true;
const styleText = `
h1 {
background: url(image.jpg) repeat no-repeat;
@@ -194,7 +179,6 @@ describe('optimizeCss', () => {
});
it('normalize-positions', async () => {
- config.minifyCss = true;
const styleText = `
h1 {
background-position: bottom left;
@@ -207,7 +191,6 @@ describe('optimizeCss', () => {
});
it('normalize-whitespace', async () => {
- config.minifyCss = true;
const styleText = `
h1 {
width: calc(10px - ( 100px / var(--test) )) ;
@@ -220,7 +203,6 @@ describe('optimizeCss', () => {
});
it('unique-selectors', async () => {
- config.minifyCss = true;
const styleText = `
h1, h3, h2, h1 {
color: red;
@@ -234,7 +216,6 @@ describe('optimizeCss', () => {
it('prevent autoprefix with null', async () => {
config.autoprefixCss = null;
- config.minifyCss = true;
const styleText = `
h1 {
box-shadow: 1px;
@@ -248,7 +229,6 @@ describe('optimizeCss', () => {
it('prevent autoprefix with false', async () => {
config.autoprefixCss = false;
- config.minifyCss = true;
const styleText = `
h1 {
box-shadow: 1px;
@@ -261,7 +241,6 @@ describe('optimizeCss', () => {
});
it('autoprefix by default', async () => {
- config.minifyCss = true;
const styleText = `
h1 {
box-shadow: 1px;
@@ -275,7 +254,6 @@ describe('optimizeCss', () => {
it('runs autoprefixerCss true config', async () => {
config.autoprefixCss = true;
- config.minifyCss = true;
const styleText = `
h1 {
box-shadow: 1px;
diff --git a/src/compiler/style/test/style.spec.ts b/src/compiler/style/test/style.spec.ts
index e23846304fe..55dc340ddbd 100644
--- a/src/compiler/style/test/style.spec.ts
+++ b/src/compiler/style/test/style.spec.ts
@@ -13,16 +13,17 @@ xdescribe('component-styles', () => {
const root = path.resolve('/');
beforeEach(async () => {
- config = mockConfig();
+ config = mockConfig({
+ minifyCss: true,
+ minifyJs: true,
+ hashFileNames: true,
+ });
compiler = new Compiler(config);
await compiler.fs.writeFile(path.join(root, 'src', 'index.html'), ``);
await compiler.fs.commit();
});
it('should add mode styles to hashed filename/minified builds', async () => {
- compiler.config.minifyJs = true;
- compiler.config.minifyCss = true;
- compiler.config.hashFileNames = true;
compiler.config.hashedFileNameLength = 2;
await compiler.fs.writeFiles({
[path.join(root, 'src', 'cmp-a.tsx')]: `@Component({
@@ -59,9 +60,6 @@ xdescribe('component-styles', () => {
});
it('should add default styles to hashed filename/minified builds', async () => {
- compiler.config.minifyJs = true;
- compiler.config.minifyCss = true;
- compiler.config.hashFileNames = true;
compiler.config.sys.generateContentHash = function () {
return 'hashed';
};
diff --git a/src/compiler/types/tests/validate-package-json.spec.ts b/src/compiler/types/tests/validate-package-json.spec.ts
index a4c1261aa9f..e9d4e3084a5 100644
--- a/src/compiler/types/tests/validate-package-json.spec.ts
+++ b/src/compiler/types/tests/validate-package-json.spec.ts
@@ -24,14 +24,17 @@ describe('validate-package-json', () => {
dir: '/dist',
typesDir: '/dist/types',
};
- config = mockConfig();
- config.devMode = false;
- config.namespace = 'SomeNamespace';
- config.fsNamespace = config.namespace.toLowerCase();
+
+ const namespace = 'SomeNamespace';
+ config = mockConfig({
+ devMode: false,
+ fsNamespace: namespace.toLowerCase(),
+ namespace,
+ packageJsonFilePath: path.join(root, 'package.json'),
+ });
compilerCtx = mockCompilerCtx(config);
buildCtx = mockBuildCtx(config, compilerCtx);
buildCtx.packageJson = {};
- config.packageJsonFilePath = path.join(root, 'package.json');
await compilerCtx.fs.writeFile(config.packageJsonFilePath, JSON.stringify(buildCtx.packageJson));
});
diff --git a/src/testing/jest/test/jest-config.spec.ts b/src/testing/jest/test/jest-config.spec.ts
index a9bfbe9715b..ee6e083a8eb 100644
--- a/src/testing/jest/test/jest-config.spec.ts
+++ b/src/testing/jest/test/jest-config.spec.ts
@@ -7,9 +7,8 @@ import path from 'path';
describe('jest-config', () => {
it('pass --maxWorkers=2 arg when --max-workers=2', () => {
const args = ['test', '--ci', '--max-workers=2'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
expect(config.flags.args).toEqual(['--ci', '--max-workers=2']);
expect(config.flags.unknownArgs).toEqual([]);
@@ -21,8 +20,7 @@ describe('jest-config', () => {
it('marks outputFile as a Jest argument', () => {
const args = ['test', '--ci', '--outputFile=path/to/my-file'];
- const config = mockValidatedConfig();
- config.testing = {};
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
expect(config.flags.args).toEqual(['--ci', '--outputFile=path/to/my-file']);
expect(config.flags.unknownArgs).toEqual([]);
@@ -32,9 +30,8 @@ describe('jest-config', () => {
it('pass --maxWorkers=2 arg when e2e test and --ci', () => {
const args = ['test', '--ci', '--e2e', '--max-workers=2'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
expect(config.flags.args).toEqual(['--ci', '--e2e', '--max-workers=2']);
expect(config.flags.unknownArgs).toEqual([]);
@@ -46,9 +43,8 @@ describe('jest-config', () => {
it('forces --maxWorkers=4 arg when e2e test and --ci', () => {
const args = ['test', '--ci', '--e2e'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
expect(config.flags.args).toEqual(['--ci', '--e2e']);
expect(config.flags.unknownArgs).toEqual([]);
@@ -60,9 +56,8 @@ describe('jest-config', () => {
it('pass --maxWorkers=2 arg to jest', () => {
const args = ['test', '--maxWorkers=2'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
expect(config.flags.args).toEqual(['--maxWorkers=2']);
expect(config.flags.unknownArgs).toEqual([]);
@@ -73,9 +68,8 @@ describe('jest-config', () => {
it('pass --ci arg to jest', () => {
const args = ['test', '--ci'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
expect(config.flags.args).toEqual(['--ci']);
expect(config.flags.unknownArgs).toEqual([]);
@@ -87,9 +81,8 @@ describe('jest-config', () => {
it('sets legacy jest options', () => {
const args = ['test'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
const jestArgv = buildJestArgv(config);
@@ -117,9 +110,8 @@ describe('jest-config', () => {
it('pass test spec arg to jest', () => {
const args = ['test', 'hello.spec.ts'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
expect(config.flags.args).toEqual(['hello.spec.ts']);
expect(config.flags.unknownArgs).toEqual(['hello.spec.ts']);
@@ -130,11 +122,12 @@ describe('jest-config', () => {
it('pass test config to jest', () => {
const args = ['test'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({
+ testing: {
+ testMatch: ['hello.spec.ts'],
+ },
+ });
config.flags = parseFlags(args, config.sys);
- config.testing = {
- testMatch: ['hello.spec.ts'],
- };
expect(config.flags.task).toBe('test');
@@ -146,12 +139,11 @@ describe('jest-config', () => {
it('set jestArgv config reporters', () => {
const rootDir = path.resolve('/');
const args = ['test'];
- const config = mockValidatedConfig();
- config.rootDir = rootDir;
+ const config = mockValidatedConfig({
+ rootDir,
+ testing: { reporters: ['default', ['jest-junit', { suiteName: 'jest tests' }]] },
+ });
config.flags = parseFlags(args, config.sys);
- config.testing = {
- reporters: ['default', ['jest-junit', { suiteName: 'jest tests' }]],
- };
const jestArgv = buildJestArgv(config);
const parsedConfig = JSON.parse(jestArgv.config) as d.JestConfig;
@@ -164,10 +156,8 @@ describe('jest-config', () => {
it('set jestArgv config rootDir', () => {
const rootDir = path.resolve('/');
const args = ['test'];
- const config = mockValidatedConfig();
- config.rootDir = rootDir;
+ const config = mockValidatedConfig({ rootDir, testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
const jestArgv = buildJestArgv(config);
const parsedConfig = JSON.parse(jestArgv.config) as d.JestConfig;
@@ -177,12 +167,8 @@ describe('jest-config', () => {
it('set jestArgv config collectCoverageFrom', () => {
const rootDir = path.resolve('/');
const args = ['test'];
- const config = mockValidatedConfig();
- config.rootDir = rootDir;
+ const config = mockValidatedConfig({ rootDir, testing: { collectCoverageFrom: ['**/*.+(ts|tsx)'] } });
config.flags = parseFlags(args, config.sys);
- config.testing = {
- collectCoverageFrom: ['**/*.+(ts|tsx)'],
- };
const jestArgv = buildJestArgv(config);
const parsedConfig = JSON.parse(jestArgv.config) as d.JestConfig;
@@ -192,9 +178,8 @@ describe('jest-config', () => {
it('passed flags should be respected over defaults', () => {
const args = ['test', '--spec', '--passWithNoTests'];
- const config = mockValidatedConfig();
+ const config = mockValidatedConfig({ testing: {} });
config.flags = parseFlags(args, config.sys);
- config.testing = {};
expect(config.flags.args).toEqual(['--spec', '--passWithNoTests']);
expect(config.flags.unknownArgs).toEqual([]);
diff --git a/src/testing/mocks.ts b/src/testing/mocks.ts
index fda5a4a9b10..b40adfb6278 100644
--- a/src/testing/mocks.ts
+++ b/src/testing/mocks.ts
@@ -2,7 +2,6 @@ import type {
BuildCtx,
Cache,
CompilerCtx,
- CompilerSystem,
Config,
LoadConfigInit,
ValidatedConfig,
@@ -21,35 +20,36 @@ import { noop } from '@utils';
import { buildEvents } from '../compiler/events';
import { createConfigFlags } from '../cli/config-flags';
-// TODO(STENCIL-486): Update `mockValidatedConfig` to accept any property found on `ValidatedConfig`
/**
* Creates a mock instance of an internal, validated Stencil configuration object
- * @param sys an optional compiler system to associate with the config. If one is not provided, one will be created for
* the caller
+ * @param overrides a partial implementation of `ValidatedConfig`. Any provided fields will override the defaults
+ * provided by this function.
* @returns the mock Stencil configuration
*/
-export function mockValidatedConfig(sys?: CompilerSystem): ValidatedConfig {
- const baseConfig = mockConfig(sys);
+export function mockValidatedConfig(overrides: Partial = {}): ValidatedConfig {
+ const baseConfig = mockConfig(overrides);
return {
...baseConfig,
flags: createConfigFlags(),
logger: mockLogger(),
outputTargets: baseConfig.outputTargets ?? [],
+ ...overrides,
};
}
-// TODO(STENCIL-486): Update `mockConfig` to accept any property found on `UnvalidatedConfig`
/**
* Creates a mock instance of a Stencil configuration entity. The mocked configuration has no guarantees around the
* types/validity of its data.
- * @param sys an optional compiler system to associate with the config. If one is not provided, one will be created for
- * the caller
+ * @param overrides a partial implementation of `UnvalidatedConfig`. Any provided fields will override the defaults
+ * provided by this function.
* @returns the mock Stencil configuration
*/
-export function mockConfig(sys?: CompilerSystem): UnvalidatedConfig {
+export function mockConfig(overrides: Partial = {}): UnvalidatedConfig {
const rootDir = path.resolve('/');
+ let { sys } = overrides;
if (!sys) {
sys = createTestingSystem();
}
@@ -57,35 +57,35 @@ export function mockConfig(sys?: CompilerSystem): UnvalidatedConfig {
return {
_isTesting: true,
-
- namespace: 'Testing',
- rootDir: rootDir,
- globalScript: null,
- devMode: true,
- enableCache: false,
buildAppCore: false,
buildDist: true,
- flags: createConfigFlags(),
- bundles: null,
- outputTargets: null,
buildEs5: false,
+ bundles: null,
+ devMode: true,
+ enableCache: false,
+ extras: {},
+ flags: createConfigFlags(),
+ globalScript: null,
hashFileNames: false,
logger: new TestingLogger(),
maxConcurrentWorkers: 0,
minifyCss: false,
minifyJs: false,
- sys,
- testing: null,
- validateTypes: false,
- extras: {},
+ namespace: 'Testing',
nodeResolve: {
customResolveOptions: {},
},
- sourceMap: true,
+ outputTargets: null,
rollupPlugins: {
before: [],
after: [],
},
+ rootDir,
+ sourceMap: true,
+ sys,
+ testing: null,
+ validateTypes: false,
+ ...overrides,
};
}
diff --git a/src/utils/test/util.spec.ts b/src/utils/test/util.spec.ts
index 8d5c23f6edb..8fc12ddc6e2 100644
--- a/src/utils/test/util.spec.ts
+++ b/src/utils/test/util.spec.ts
@@ -6,8 +6,7 @@ import { stubDiagnostic } from '../../dev-server/test/Diagnostic.stub';
describe('util', () => {
describe('generatePreamble', () => {
it('generates a comment with a single line preamble', () => {
- const testConfig = mockConfig();
- testConfig.preamble = 'I am Stencil';
+ const testConfig = mockConfig({ preamble: 'I am Stencil' });
const result = util.generatePreamble(testConfig);
@@ -17,8 +16,7 @@ describe('util', () => {
});
it('generates a comment with a multi-line preamble', () => {
- const testConfig = mockConfig();
- testConfig.preamble = 'I am Stencil\nHear me roar';
+ const testConfig = mockConfig({ preamble: 'I am Stencil\nHear me roar' });
const result = util.generatePreamble(testConfig);
@@ -37,8 +35,7 @@ describe('util', () => {
});
it('returns an empty string a null preamble is provided', () => {
- const testConfig = mockConfig();
- testConfig.preamble = null;
+ const testConfig = mockConfig({ preamble: null });
const result = util.generatePreamble(testConfig);
@@ -46,8 +43,7 @@ describe('util', () => {
});
it('returns an empty string if an empty preamble is provided', () => {
- const testConfig = mockConfig();
- testConfig.preamble = '';
+ const testConfig = mockConfig({ preamble: '' });
const result = util.generatePreamble(testConfig);