From 07bb79387ff7485ae47ba789a65228a6efa3dbc6 Mon Sep 17 00:00:00 2001 From: miherlosev Date: Thu, 23 Dec 2021 13:55:07 +0300 Subject: [PATCH] fix 'Testcafe wrongly shows "filter" warning' (close #6620) --- src/configuration/configuration-base.ts | 8 +- src/configuration/default-values.ts | 1 + src/configuration/option-source.ts | 1 + src/configuration/testcafe-configuration.ts | 21 +- test/server/configuration-test.js | 679 ++++++++++---------- 5 files changed, 372 insertions(+), 338 deletions(-) diff --git a/src/configuration/configuration-base.ts b/src/configuration/configuration-base.ts index c17d0fe65d..e7995357cf 100644 --- a/src/configuration/configuration-base.ts +++ b/src/configuration/configuration-base.ts @@ -1,6 +1,7 @@ -import { isAbsolute, extname } from 'path'; +import { extname, isAbsolute } from 'path'; import debug from 'debug'; import JSON5 from 'json5'; + import { castArray, cloneDeep, @@ -8,7 +9,7 @@ import { mergeWith, } from 'lodash'; -import { stat, readFile } from '../utils/promisified-functions'; +import { readFile, stat } from '../utils/promisified-functions'; import Option from './option'; import OptionSource from './option-source'; import resolvePathRelativelyCwd from '../utils/resolve-path-relatively-cwd'; @@ -268,6 +269,9 @@ export default class Configuration { } protected _addOverriddenOptionIfNecessary (value1: OptionValue, value2: OptionValue, source: OptionSource, optionName: string): void { + if (source === OptionSource.Default) + return; + if (value1 === void 0 || value2 === void 0 || value1 === value2 || source !== OptionSource.Configuration) return; diff --git a/src/configuration/default-values.ts b/src/configuration/default-values.ts index 60c520fdac..1039e5868b 100644 --- a/src/configuration/default-values.ts +++ b/src/configuration/default-values.ts @@ -20,6 +20,7 @@ export const DEFAULT_RETRY_TEST_PAGES = false; export const DEFAULT_DISABLE_HTTP2 = false; export const DEFAULT_PROXYLESS = false; export const DEFAULT_SCREENSHOT_THUMBNAILS = true; +export const DEFAULT_FILTER_FN = null; export const DEFAULT_TYPESCRIPT_COMPILER_OPTIONS: Dictionary = { experimentalDecorators: true, diff --git a/src/configuration/option-source.ts b/src/configuration/option-source.ts index e9db29f49f..1c8476ef0c 100644 --- a/src/configuration/option-source.ts +++ b/src/configuration/option-source.ts @@ -1,4 +1,5 @@ enum OptionSource { + Default = 'Default', Configuration = 'Configuration', Input = 'Input' } diff --git a/src/configuration/testcafe-configuration.ts b/src/configuration/testcafe-configuration.ts index 5dbfe86fd6..58f9ab702a 100644 --- a/src/configuration/testcafe-configuration.ts +++ b/src/configuration/testcafe-configuration.ts @@ -12,18 +12,20 @@ import resolvePathRelativelyCwd from '../utils/resolve-path-relatively-cwd'; import { DEFAULT_APP_INIT_DELAY, DEFAULT_CONCURRENCY_VALUE, - DEFAULT_SPEED_VALUE, - DEFAULT_TIMEOUT, - DEFAULT_SOURCE_DIRECTORIES, DEFAULT_DEVELOPMENT_MODE, - DEFAULT_RETRY_TEST_PAGES, DEFAULT_DISABLE_HTTP2, + DEFAULT_FILTER_FN, DEFAULT_PROXYLESS, + DEFAULT_RETRY_TEST_PAGES, DEFAULT_SCREENSHOT_THUMBNAILS, + DEFAULT_SOURCE_DIRECTORIES, + DEFAULT_SPEED_VALUE, + DEFAULT_TIMEOUT, getDefaultCompilerOptions, } from './default-values'; import OptionSource from './option-source'; + import { Dictionary, FilterOption, @@ -162,8 +164,8 @@ export default class TestCafeConfiguration extends Configuration { return result; } - private _prepareFlag (name: string): void { - const option = this._ensureOption(name, void 0, OptionSource.Configuration); + private _prepareFlag (name: string, source = OptionSource.Configuration): void { + const option = this._ensureOption(name, void 0, source); option.value = !!option.value; } @@ -173,7 +175,7 @@ export default class TestCafeConfiguration extends Configuration { } private _prepareInitFlags (): void { - OPTION_INIT_FLAG_NAMES.forEach(name => this._prepareFlag(name)); + OPTION_INIT_FLAG_NAMES.forEach(name => this._prepareFlag(name, OptionSource.Default)); } private async _normalizeOptionsAfterLoad (): Promise { @@ -187,7 +189,7 @@ export default class TestCafeConfiguration extends Configuration { } private _prepareFilterFn (): void { - const filterOption = this._ensureOption(OPTION_NAMES.filter, null, OptionSource.Configuration); + const filterOption = this._ensureOption(OPTION_NAMES.filter, DEFAULT_FILTER_FN, OptionSource.Default); if (!filterOption.value) return; @@ -200,7 +202,8 @@ export default class TestCafeConfiguration extends Configuration { if (filterOptionValue.fixtureGrep) filterOptionValue.fixtureGrep = getGrepOptions(OPTION_NAMES.filterFixtureGrep, filterOptionValue.fixtureGrep as string); - filterOption.value = getFilterFn(filterOption.value) as Function; + filterOption.value = getFilterFn(filterOption.value) as Function; + filterOption.source = OptionSource.Configuration; } private _ensureScreenshotOptions (): void { diff --git a/test/server/configuration-test.js b/test/server/configuration-test.js index ccc4756c0c..09b95b8629 100644 --- a/test/server/configuration-test.js +++ b/test/server/configuration-test.js @@ -1,5 +1,6 @@ /*eslint-disable no-console */ -const { cloneDeep } = require('lodash'); +const { cloneDeep, noop } = require('lodash'); + const { expect } = require('chai'); const fs = require('fs'); const tmp = require('tmp'); @@ -47,43 +48,16 @@ describe('TestCafeConfiguration', function () { const testCafeConfiguration = new TestCafeConfiguration(); let keyFileContent = null; + let keyFile = null; consoleWrapper.init(); tmp.setGracefulCleanup(); beforeEach(() => { - const keyFile = tmp.fileSync(); - + keyFile = tmp.fileSync(); keyFileContent = Buffer.from(nanoid()); - fs.writeFileSync(keyFile.name, keyFileContent); - createJSONTestCafeConfigurationFile({ - 'hostname': '123.456.789', - 'port1': 1234, - 'port2': 5678, - 'src': 'path1/folder', - 'ssl': { - 'key': keyFile.name, - 'rejectUnauthorized': 'true', - }, - 'browsers': 'remote', - 'concurrency': 0.5, - 'filter': { - 'fixture': 'testFixture', - 'test': 'some test', - 'testGrep': 'test\\d', - 'fixtureGrep': 'fixture\\d', - 'testMeta': { test: 'meta' }, - 'fixtureMeta': { fixture: 'meta' }, - }, - 'clientScripts': 'test-client-script.js', - 'disableHttp2': true, - 'proxyless': true, - 'dashboard': { - 'token': 'qwe.rty', - 'noVideoUpload': true, - }, - }); + fs.writeFileSync(keyFile.name, keyFileContent); }); afterEach(async () => { @@ -93,394 +67,445 @@ describe('TestCafeConfiguration', function () { consoleWrapper.messages.clear(); }); - describe('Init', () => { - describe('Exists', () => { - it('Config is not well-formed', () => { - const filePath = testCafeConfiguration.defaultPaths[jsonConfigIndex]; - - fs.writeFileSync(filePath, '{'); - consoleWrapper.wrap(); - - return testCafeConfiguration.init() - .then(() => { - consoleWrapper.unwrap(); - - expect(testCafeConfiguration.getOption('hostname')).eql(void 0); - expect(consoleWrapper.messages.log).contains(`Failed to parse the '${testCafeConfiguration.defaultPaths[jsonConfigIndex]}' file.`); - }); + describe('Basic', function () { + beforeEach(() => { + createJSONTestCafeConfigurationFile({ + 'hostname': '123.456.789', + 'port1': 1234, + 'port2': 5678, + 'src': 'path1/folder', + 'ssl': { + 'key': keyFile.name, + 'rejectUnauthorized': 'true', + }, + 'browsers': 'remote', + 'concurrency': 0.5, + 'filter': { + 'fixture': 'testFixture', + 'test': 'some test', + 'testGrep': 'test\\d', + 'fixtureGrep': 'fixture\\d', + 'testMeta': { test: 'meta' }, + 'fixtureMeta': { fixture: 'meta' }, + }, + 'clientScripts': 'test-client-script.js', + 'disableHttp2': true, + 'proxyless': true, + 'dashboard': { + 'token': 'qwe.rty', + 'noVideoUpload': true, + }, }); + }); - it('Options', () => { - return testCafeConfiguration.init() - .then(() => { - expect(testCafeConfiguration.getOption('hostname')).eql('123.456.789'); - expect(testCafeConfiguration.getOption('port1')).eql(1234); - - const ssl = testCafeConfiguration.getOption('ssl'); - - expect(ssl.key).eql(keyFileContent); - expect(ssl.rejectUnauthorized).eql(true); - expect(testCafeConfiguration.getOption('src')).eql(['path1/folder']); - expect(testCafeConfiguration.getOption('browsers')).to.be.an('array').that.not.empty; - expect(testCafeConfiguration.getOption('browsers')[0]).to.include({ providerName: 'remote' }); - expect(testCafeConfiguration.getOption('concurrency')).eql(0.5); - expect(testCafeConfiguration.getOption('filter')).to.be.a('function'); - expect(testCafeConfiguration.getOption('filter').testGrep.test('test1')).to.be.true; - expect(testCafeConfiguration.getOption('filter').fixtureGrep.test('fixture1')).to.be.true; - expect(testCafeConfiguration.getOption('filter').testMeta).to.be.deep.equal({ test: 'meta' }); - expect(testCafeConfiguration.getOption('filter').fixtureMeta).to.be.deep.equal({ fixture: 'meta' }); - expect(testCafeConfiguration.getOption('clientScripts')).eql([ 'test-client-script.js' ]); - expect(testCafeConfiguration.getOption('disableHttp2')).to.be.true; - expect(testCafeConfiguration.getOption('proxyless')).to.be.true; - expect(testCafeConfiguration.getOption('dashboard')).eql({ token: 'qwe.rty', noVideoUpload: true }); - }); - }); + describe('Init', () => { + describe('Exists', () => { + it('Config is not well-formed', () => { + const filePath = testCafeConfiguration.defaultPaths[jsonConfigIndex]; - it('"Reporter" option', () => { - let optionValue = null; + fs.writeFileSync(filePath, '{'); + consoleWrapper.wrap(); - createJSONTestCafeConfigurationFile({ - reporter: 'json', + return testCafeConfiguration.init() + .then(() => { + consoleWrapper.unwrap(); + + expect(testCafeConfiguration.getOption('hostname')).eql(void 0); + expect(consoleWrapper.messages.log).contains(`Failed to parse the '${testCafeConfiguration.defaultPaths[jsonConfigIndex]}' file.`); + }); }); - return testCafeConfiguration - .init() - .then(() => { - optionValue = testCafeConfiguration.getOption('reporter'); + it('Options', () => { + return testCafeConfiguration.init() + .then(() => { + expect(testCafeConfiguration.getOption('hostname')).eql('123.456.789'); + expect(testCafeConfiguration.getOption('port1')).eql(1234); + + const ssl = testCafeConfiguration.getOption('ssl'); + + expect(ssl.key).eql(keyFileContent); + expect(ssl.rejectUnauthorized).eql(true); + expect(testCafeConfiguration.getOption('src')).eql(['path1/folder']); + expect(testCafeConfiguration.getOption('browsers')).to.be.an('array').that.not.empty; + expect(testCafeConfiguration.getOption('browsers')[0]).to.include({ providerName: 'remote' }); + expect(testCafeConfiguration.getOption('concurrency')).eql(0.5); + expect(testCafeConfiguration.getOption('filter')).to.be.a('function'); + expect(testCafeConfiguration.getOption('filter').testGrep.test('test1')).to.be.true; + expect(testCafeConfiguration.getOption('filter').fixtureGrep.test('fixture1')).to.be.true; + expect(testCafeConfiguration.getOption('filter').testMeta).to.be.deep.equal({ test: 'meta' }); + expect(testCafeConfiguration.getOption('filter').fixtureMeta).to.be.deep.equal({ fixture: 'meta' }); + expect(testCafeConfiguration.getOption('clientScripts')).eql([ 'test-client-script.js' ]); + expect(testCafeConfiguration.getOption('disableHttp2')).to.be.true; + expect(testCafeConfiguration.getOption('proxyless')).to.be.true; + expect(testCafeConfiguration.getOption('dashboard')).eql({ token: 'qwe.rty', noVideoUpload: true }); + }); + }); - expect(optionValue.length).eql(1); - expect(optionValue[0].name).eql('json'); + it('"Reporter" option', () => { + let optionValue = null; - createJSONTestCafeConfigurationFile({ - reporter: ['json', 'minimal'], - }); + createJSONTestCafeConfigurationFile({ + reporter: 'json', + }); - return testCafeConfiguration.init(); - }) - .then(() => { - optionValue = testCafeConfiguration.getOption('reporter'); + return testCafeConfiguration + .init() + .then(() => { + optionValue = testCafeConfiguration.getOption('reporter'); - expect(optionValue.length).eql(2); - expect(optionValue[0].name).eql('json'); - expect(optionValue[1].name).eql('minimal'); + expect(optionValue.length).eql(1); + expect(optionValue[0].name).eql('json'); - createJSONTestCafeConfigurationFile({ - reporter: [ { - name: 'json', - file: 'path/to/file', - }], - }); + createJSONTestCafeConfigurationFile({ + reporter: ['json', 'minimal'], + }); - return testCafeConfiguration.init(); - }) - .then(() => { - optionValue = testCafeConfiguration.getOption('reporter'); + return testCafeConfiguration.init(); + }) + .then(() => { + optionValue = testCafeConfiguration.getOption('reporter'); - expect(optionValue.length).eql(1); - expect(optionValue[0].name).eql('json'); - expect(optionValue[0].file).eql('path/to/file'); - }); - }); + expect(optionValue.length).eql(2); + expect(optionValue[0].name).eql('json'); + expect(optionValue[1].name).eql('minimal'); - describe('Screenshot options', () => { - it('`mergeOptions` overrides config values', () => { - createJSONTestCafeConfigurationFile({ - 'screenshots': { - 'path': 'screenshot-path', - 'pathPattern': 'screenshot-path-pattern', - 'takeOnFails': true, - 'fullPage': true, - 'thumbnails': true, - }, - }); + createJSONTestCafeConfigurationFile({ + reporter: [ { + name: 'json', + file: 'path/to/file', + }], + }); - return testCafeConfiguration.init() + return testCafeConfiguration.init(); + }) .then(() => { - testCafeConfiguration.mergeOptions({ - screenshots: { - path: 'modified-path', - pathPattern: 'modified-pattern', - takeOnFails: false, - fullPage: false, - thumbnails: false, - }, - }); + optionValue = testCafeConfiguration.getOption('reporter'); + + expect(optionValue.length).eql(1); + expect(optionValue[0].name).eql('json'); + expect(optionValue[0].file).eql('path/to/file'); + }); + }); - expect(testCafeConfiguration.getOption('screenshots')).eql({ + describe('Screenshot options', () => { + it('`mergeOptions` overrides config values', async () => { + createJSONTestCafeConfigurationFile({ + 'screenshots': { + 'path': 'screenshot-path', + 'pathPattern': 'screenshot-path-pattern', + 'takeOnFails': true, + 'fullPage': true, + 'thumbnails': true, + }, + }); + + await testCafeConfiguration.init(); + + testCafeConfiguration.mergeOptions({ + screenshots: { path: 'modified-path', pathPattern: 'modified-pattern', takeOnFails: false, fullPage: false, thumbnails: false, - }); + }, + }); - expect(testCafeConfiguration._overriddenOptions).eql([ - 'screenshots.path', - 'screenshots.pathPattern', - 'screenshots.takeOnFails', - 'screenshots.fullPage', - 'screenshots.thumbnails', - ]); + expect(testCafeConfiguration.getOption('screenshots')).eql({ + path: 'modified-path', + pathPattern: 'modified-pattern', + takeOnFails: false, + fullPage: false, + thumbnails: false, }); - }); - it('`mergeOptions` merges config values', () => { - createJSONTestCafeConfigurationFile({ - 'screenshots': { - 'path': 'screenshot-path', - 'pathPattern': 'screenshot-path-pattern', - }, + expect(testCafeConfiguration._overriddenOptions).eql([ + 'screenshots.path', + 'screenshots.pathPattern', + 'screenshots.takeOnFails', + 'screenshots.fullPage', + 'screenshots.thumbnails', + ]); }); - return testCafeConfiguration.init() - .then(() => { - testCafeConfiguration.mergeOptions({ - screenshots: { - path: 'modified-path', - pathPattern: void 0, - takeOnFails: false, - }, - }); + it('`mergeOptions` merges config values', async () => { + createJSONTestCafeConfigurationFile({ + 'screenshots': { + 'path': 'screenshot-path', + 'pathPattern': 'screenshot-path-pattern', + }, + }); + + await testCafeConfiguration.init(); - expect(testCafeConfiguration.getOption('screenshots')).eql({ + testCafeConfiguration.mergeOptions({ + screenshots: { path: 'modified-path', - pathPattern: 'screenshot-path-pattern', + pathPattern: void 0, takeOnFails: false, - }); - - expect(testCafeConfiguration._overriddenOptions).eql(['screenshots.path']); + }, }); - }); - it('`mergeOptions` with an empty object does not override anything', () => { - createJSONTestCafeConfigurationFile({ - 'screenshots': { - 'path': 'screenshot-path', - 'pathPattern': 'screenshot-path-pattern', - }, + expect(testCafeConfiguration.getOption('screenshots')).eql({ + path: 'modified-path', + pathPattern: 'screenshot-path-pattern', + takeOnFails: false, + }); + expect(testCafeConfiguration._overriddenOptions).eql(['screenshots.path']); }); - return testCafeConfiguration.init() - .then(() => { + it('`mergeOptions` with an empty object does not override anything', async () => { + createJSONTestCafeConfigurationFile({ + 'screenshots': { + 'path': 'screenshot-path', + 'pathPattern': 'screenshot-path-pattern', + }, + }); - testCafeConfiguration.mergeOptions({ }); + await testCafeConfiguration.init(); - testCafeConfiguration.mergeOptions({ screenshots: {} }); + testCafeConfiguration.mergeOptions({ }); + testCafeConfiguration.mergeOptions({ screenshots: {} }); - expect(testCafeConfiguration.getOption('screenshots')).eql({ - path: 'screenshot-path', - pathPattern: 'screenshot-path-pattern', - }); + expect(testCafeConfiguration.getOption('screenshots')).eql({ + path: 'screenshot-path', + pathPattern: 'screenshot-path-pattern', }); - }); - - it('both `screenshots` options exist in config', () => { - createJSONTestCafeConfigurationFile({ - 'screenshots': { - 'path': 'screenshot-path-1', - 'pathPattern': 'screenshot-path-pattern-1', - 'takeOnFails': true, - 'fullPage': true, - 'thumbnails': true, - }, - 'screenshotPath': 'screenshot-path-2', - 'screenshotPathPattern': 'screenshot-path-pattern-2', - 'takeScreenshotsOnFails': false, }); - return testCafeConfiguration.init() - .then(() => { - expect(testCafeConfiguration._overriddenOptions.length).eql(0); - - expect(testCafeConfiguration.getOption('screenshots')).eql({ - path: 'screenshot-path-1', - pathPattern: 'screenshot-path-pattern-1', - takeOnFails: true, - fullPage: true, - thumbnails: true, - }); + it('both `screenshots` options exist in config', async () => { + createJSONTestCafeConfigurationFile({ + 'screenshots': { + 'path': 'screenshot-path-1', + 'pathPattern': 'screenshot-path-pattern-1', + 'takeOnFails': true, + 'fullPage': true, + 'thumbnails': true, + }, + 'screenshotPath': 'screenshot-path-2', + 'screenshotPathPattern': 'screenshot-path-pattern-2', + 'takeScreenshotsOnFails': false, + }); - expect(testCafeConfiguration.getOption('screenshotPath')).eql('screenshot-path-2'); - expect(testCafeConfiguration.getOption('screenshotPathPattern')).eql('screenshot-path-pattern-2'); - expect(testCafeConfiguration.getOption('takeScreenshotsOnFails')).eql(false); + await testCafeConfiguration.init(); + + expect(testCafeConfiguration._overriddenOptions.length).eql(0); + expect(testCafeConfiguration.getOption('screenshots')).eql({ + path: 'screenshot-path-1', + pathPattern: 'screenshot-path-pattern-1', + takeOnFails: true, + fullPage: true, + thumbnails: true, }); + expect(testCafeConfiguration.getOption('screenshotPath')).eql('screenshot-path-2'); + expect(testCafeConfiguration.getOption('screenshotPathPattern')).eql('screenshot-path-pattern-2'); + expect(testCafeConfiguration.getOption('takeScreenshotsOnFails')).eql(false); + }); }); - }); - it("Shouldn't change filter option with function", async () => { - fs.writeFileSync(TestCafeConfiguration.FILENAMES[jsConfigIndex], `module.exports = {filter: (testName, fixtureName, fixturePath, testMeta, fixtureMeta) => true}`); + it("Shouldn't change filter option with function", async () => { + fs.writeFileSync(TestCafeConfiguration.FILENAMES[jsConfigIndex], `module.exports = {filter: (testName, fixtureName, fixturePath, testMeta, fixtureMeta) => true}`); - await testCafeConfiguration.init(); + await testCafeConfiguration.init(); - expect(testCafeConfiguration.getOption('filter')).to.be.a('function'); - expect(testCafeConfiguration.getOption('filter')()).to.be.true; - }); - - it('Should warn message on multiple configuration files', async () => { - createJsTestCafeConfigurationFile({ - 'hostname': '123.456.789', - 'port1': 1234, - 'port2': 5678, - 'src': 'path1/folder', - 'browser': 'ie', + expect(testCafeConfiguration.getOption('filter')).to.be.a('function'); + expect(testCafeConfiguration.getOption('filter')()).to.be.true; }); - consoleWrapper.wrap(); - await testCafeConfiguration.init(); - consoleWrapper.unwrap(); + it('Should warn message on multiple configuration files', async () => { + createJsTestCafeConfigurationFile({ + 'hostname': '123.456.789', + 'port1': 1234, + 'port2': 5678, + 'src': 'path1/folder', + 'browser': 'ie', + }); - const expectedMessage = - `There are multiple configuration files found, TestCafe will only use one. The file "${pathUtil.resolve('.testcaferc.js')}" will be used.\n` + - 'The priority order is as follows:\n' + - `1. ${pathUtil.resolve('.testcaferc.js')}\n` + - `2. ${pathUtil.resolve('.testcaferc.json')}`; + consoleWrapper.wrap(); + await testCafeConfiguration.init(); + consoleWrapper.unwrap(); - expect(consoleWrapper.messages.log).eql(expectedMessage); - }); + const expectedMessage = + `There are multiple configuration files found, TestCafe will only use one. The file "${pathUtil.resolve('.testcaferc.js')}" will be used.\n` + + 'The priority order is as follows:\n' + + `1. ${pathUtil.resolve('.testcaferc.js')}\n` + + `2. ${pathUtil.resolve('.testcaferc.json')}`; - it('Should read JS config file if JSON and JS default files exist', async () => { - createJsTestCafeConfigurationFile({ - 'jsConfig': true, - }); - createJSONTestCafeConfigurationFile({ - 'jsConfig': false, + expect(consoleWrapper.messages.log).eql(expectedMessage); }); - await testCafeConfiguration.init(); + it('Should read JS config file if JSON and JS default files exist', async () => { + createJsTestCafeConfigurationFile({ + 'jsConfig': true, + }); + createJSONTestCafeConfigurationFile({ + 'jsConfig': false, + }); + + await testCafeConfiguration.init(); - expect(testCafeConfiguration.getOption('jsConfig')).to.be.true; + expect(testCafeConfiguration.getOption('jsConfig')).to.be.true; + }); }); - }); - it('File doesn\'t exists', () => { - fs.unlinkSync(TestCafeConfiguration.FILENAMES[jsonConfigIndex]); + it('File doesn\'t exists', () => { + fs.unlinkSync(TestCafeConfiguration.FILENAMES[jsonConfigIndex]); - const defaultOptions = cloneDeep(testCafeConfiguration._options); + const defaultOptions = cloneDeep(testCafeConfiguration._options); - return testCafeConfiguration.init() - .then(() => { - expect(testCafeConfiguration._options).to.deep.equal(defaultOptions); - }); - }); + return testCafeConfiguration.init() + .then(() => { + expect(testCafeConfiguration._options).to.deep.equal(defaultOptions); + }); + }); - it('Explicitly specified configuration file doesn\'t exist', async () => { - let message = null; + it('Explicitly specified configuration file doesn\'t exist', async () => { + let message = null; - const nonExistingConfiguration = new TestCafeConfiguration('non-existing-path'); + const nonExistingConfiguration = new TestCafeConfiguration('non-existing-path'); - try { - await nonExistingConfiguration.init(); - } - catch (err) { - message = err.message; - } + try { + await nonExistingConfiguration.init(); + } + catch (err) { + message = err.message; + } - expect(message).eql(`"${nonExistingConfiguration.filePath}" is not a valid path to the TestCafe configuration file. Make sure the configuration file exists and you spell the path name correctly.`); + expect(message).eql(`"${nonExistingConfiguration.filePath}" is not a valid path to the TestCafe configuration file. Make sure the configuration file exists and you spell the path name correctly.`); + }); }); - }); - describe('Merge options', () => { - it('One', () => { - consoleWrapper.wrap(); + describe('Merge options', () => { + it('One', () => { + consoleWrapper.wrap(); - return testCafeConfiguration.init() - .then(() => { - testCafeConfiguration.mergeOptions({ 'hostname': 'anotherHostname' }); - testCafeConfiguration.notifyAboutOverriddenOptions(); + return testCafeConfiguration.init() + .then(() => { + testCafeConfiguration.mergeOptions({ 'hostname': 'anotherHostname' }); + testCafeConfiguration.notifyAboutOverriddenOptions(); - consoleWrapper.unwrap(); + consoleWrapper.unwrap(); - expect(testCafeConfiguration.getOption('hostname')).eql('anotherHostname'); - expect(consoleWrapper.messages.log).eql('The "hostname" option from the configuration file will be ignored.'); - }); - }); + expect(testCafeConfiguration.getOption('hostname')).eql('anotherHostname'); + expect(consoleWrapper.messages.log).eql('The "hostname" option from the configuration file will be ignored.'); + }); + }); - it('Many', () => { - consoleWrapper.wrap(); + it('Many', () => { + consoleWrapper.wrap(); - return testCafeConfiguration.init() - .then(() => { - testCafeConfiguration.mergeOptions({ - 'hostname': 'anotherHostname', - 'port1': 'anotherPort1', - 'port2': 'anotherPort2', - }); + return testCafeConfiguration.init() + .then(() => { + testCafeConfiguration.mergeOptions({ + 'hostname': 'anotherHostname', + 'port1': 'anotherPort1', + 'port2': 'anotherPort2', + }); - testCafeConfiguration.notifyAboutOverriddenOptions(); + testCafeConfiguration.notifyAboutOverriddenOptions(); - consoleWrapper.unwrap(); + consoleWrapper.unwrap(); - expect(testCafeConfiguration.getOption('hostname')).eql('anotherHostname'); - expect(testCafeConfiguration.getOption('port1')).eql('anotherPort1'); - expect(testCafeConfiguration.getOption('port2')).eql('anotherPort2'); - expect(consoleWrapper.messages.log).eql('The "hostname", "port1", and "port2" options from the configuration file will be ignored.'); - }); - }); + expect(testCafeConfiguration.getOption('hostname')).eql('anotherHostname'); + expect(testCafeConfiguration.getOption('port1')).eql('anotherPort1'); + expect(testCafeConfiguration.getOption('port2')).eql('anotherPort2'); + expect(consoleWrapper.messages.log).eql('The "hostname", "port1", and "port2" options from the configuration file will be ignored.'); + }); + }); - it('Should ignore an option with the "undefined" value', () => { - return testCafeConfiguration.init() - .then(() => { - testCafeConfiguration.mergeOptions({ 'hostname': void 0 }); + it('Should ignore an option with the "undefined" value', () => { + return testCafeConfiguration.init() + .then(() => { + testCafeConfiguration.mergeOptions({ 'hostname': void 0 }); - expect(testCafeConfiguration.getOption('hostname')).eql('123.456.789'); - }); + expect(testCafeConfiguration.getOption('hostname')).eql('123.456.789'); + }); + }); }); - }); - describe('Should copy value from "tsConfigPath" to compiler options', () => { - it('only tsConfigPath is specified', async () => { - const configuration = new TestCafeConfiguration(); - const runner = new RunnerCtor({ configuration }); + describe('Should copy value from "tsConfigPath" to compiler options', () => { + it('only tsConfigPath is specified', async () => { + const configuration = new TestCafeConfiguration(); + const runner = new RunnerCtor({ configuration }); - await runner.tsConfigPath('path-to-ts-config'); - await runner._setConfigurationOptions(); - await runner._setBootstrapperOptions(); + await runner.tsConfigPath('path-to-ts-config'); + await runner._setConfigurationOptions(); + await runner._setBootstrapperOptions(); - expect(runner.configuration.getOption(OptionNames.compilerOptions)).eql({ - 'typescript': { - configPath: 'path-to-ts-config', - }, + expect(runner.configuration.getOption(OptionNames.compilerOptions)).eql({ + 'typescript': { + configPath: 'path-to-ts-config', + }, + }); }); - }); - it('tsConfigPath is specified and compiler options are "undefined"', async () => { - const configuration = new TestCafeConfiguration(); - const runner = new RunnerCtor({ configuration }); + it('tsConfigPath is specified and compiler options are "undefined"', async () => { + const configuration = new TestCafeConfiguration(); + const runner = new RunnerCtor({ configuration }); - await runner - .tsConfigPath('path-to-ts-config') - .compilerOptions(void 0); // emulate command-line run - await runner._setConfigurationOptions(); - await runner._setBootstrapperOptions(); + await runner + .tsConfigPath('path-to-ts-config') + .compilerOptions(void 0); // emulate command-line run + await runner._setConfigurationOptions(); + await runner._setBootstrapperOptions(); - expect(runner.configuration.getOption(OptionNames.compilerOptions)).eql({ - 'typescript': { - configPath: 'path-to-ts-config', - }, + expect(runner.configuration.getOption(OptionNames.compilerOptions)).eql({ + 'typescript': { + configPath: 'path-to-ts-config', + }, + }); }); - }); - it('both "tsConfigPath" and compiler options are specified', async () => { - const configuration = new TestCafeConfiguration(); - const runner = new RunnerCtor({ configuration }); + it('both "tsConfigPath" and compiler options are specified', async () => { + const configuration = new TestCafeConfiguration(); + const runner = new RunnerCtor({ configuration }); - await runner - .tsConfigPath('path-to-ts-config') - .compilerOptions({ + await runner + .tsConfigPath('path-to-ts-config') + .compilerOptions({ + 'typescript': { + configPath: 'path-in-compiler-options', + }, + }); + await runner._setConfigurationOptions(); + await runner._setBootstrapperOptions(); + + expect(runner.configuration.getOption(OptionNames.compilerOptions)).eql({ 'typescript': { configPath: 'path-in-compiler-options', }, }); - await runner._setConfigurationOptions(); - await runner._setBootstrapperOptions(); - - expect(runner.configuration.getOption(OptionNames.compilerOptions)).eql({ - 'typescript': { - configPath: 'path-in-compiler-options', - }, }); }); }); + + describe('Default values', function () { + beforeEach(() => { + createJSONTestCafeConfigurationFile({ }); + }); + + async function testInitWithMergeOption (opts) { + consoleWrapper.wrap(); + + await testCafeConfiguration.init(); + + consoleWrapper.unwrap(); + + testCafeConfiguration.mergeOptions(opts); + } + + it('Filter', async () => { + await testInitWithMergeOption({ filter: noop }); + + expect(testCafeConfiguration._overriddenOptions).eql([]); + }); + + it('Init flags', async () => { + await testInitWithMergeOption({ developmentMode: true }); + + expect(testCafeConfiguration._overriddenOptions).eql([]); + }); + }); }); describe('TypeScriptConfiguration', function () {