diff --git a/.hgignore b/.hgignore index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_LmhnaWdub3Jl..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_LmhnaWdub3Jl 100644 --- a/.hgignore +++ b/.hgignore @@ -14,3 +14,4 @@ esm/ test/package-lock.json coverage/ +.nyc_output/ diff --git a/.npmignore b/.npmignore index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_Lm5wbWlnbm9yZQ==..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_Lm5wbWlnbm9yZQ== 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,7 @@ test/ patches/ coverage/ +.nyc_outpout/ .editorconfig babel.config.json .gitlab-ci.yml diff --git a/src/tags/cmdline-option.mjs b/src/tags/cmdline-option.mjs index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_c3JjL3RhZ3MvY21kbGluZS1vcHRpb24ubWpz..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_c3JjL3RhZ3MvY21kbGluZS1vcHRpb24ubWpz 100644 --- a/src/tags/cmdline-option.mjs +++ b/src/tags/cmdline-option.mjs @@ -1,6 +1,7 @@ import { inspect } from 'util' +import Joi from '@hapi/joi' import yargs from 'yargs' import { createTag } from '../create-tag.mjs' class CmdlineOption { @@ -2,9 +3,13 @@ import yargs from 'yargs' import { createTag } from '../create-tag.mjs' class CmdlineOption { - constructor ({ name, ...options }) { + constructor (data) { + Joi.assert(data, Joi.object({ name: Joi.string().min(1).required() }).unknown()) + + const { name, ...options } = data + this.name = name this.options = options @@ -29,7 +34,7 @@ return new CmdlineOption({ name }) }, fromSeq () { - throw new Error('Can only be constructed from a scalar!') + throw new Error('Can not be constructed from a sequence.') }, toYAML (data) { if (!data.options) { diff --git a/src/tags/fallback.mjs b/src/tags/fallback.mjs index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_c3JjL3RhZ3MvZmFsbGJhY2subWpz..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_c3JjL3RhZ3MvZmFsbGJhY2subWpz 100644 --- a/src/tags/fallback.mjs +++ b/src/tags/fallback.mjs @@ -1,6 +1,7 @@ import { inspect } from 'util' +import Joi from '@hapi/joi' import { createTag } from '../create-tag.mjs' class Fallback { constructor (values) { @@ -2,10 +3,11 @@ import { createTag } from '../create-tag.mjs' class Fallback { constructor (values) { + Joi.assert(values, Joi.array().min(1)) this.values = values } get valueIndex () { return this.values.findIndex(val => { @@ -7,7 +9,7 @@ this.values = values } get valueIndex () { return this.values.findIndex(val => { - val = val?.valueOf?.() + val = val?.valueOf() return val !== null && val !== undefined @@ -13,5 +15,5 @@ return val !== null && val !== undefined - }) ?? (this.values.length - 1) + }) } get value () { @@ -15,7 +17,7 @@ } get value () { - return this.values[this.valueIndex]?.valueOf?.() + return this.values[this.valueIndex]?.valueOf() } valueOf () { diff --git a/test/index.spec.js b/test/index.spec.js index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_dGVzdC9pbmRleC5zcGVjLmpz..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC9pbmRleC5zcGVjLmpz 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -3,5 +3,4 @@ const chaiAsPromised = require('chai-as-promised') const { dirname, join, resolve, sep } = require('path') const { sync: glob } = require('glob') -const { readFile } = require('fs/promises') const { readFileSync } = require('fs') @@ -7,4 +6,5 @@ const { readFileSync } = require('fs') +const { regexpTag } = require('../commonjs/tags/regexp') const YAML = require('yaml') const expect = chai.expect @@ -12,4 +12,9 @@ const loadConfig = require('./worker/load-config') +const parseYamlFile = path => { + path = resolve(__dirname, path) + return YAML.parse(readFileSync(path, 'utf8'), { customTags: [regexpTag] }) +} + const wrapTests = file => { @@ -15,5 +20,5 @@ const wrapTests = file => { - const testInfo = YAML.parse(readFileSync(resolve(__dirname, file), 'utf8')) + const testInfo = parseYamlFile(file) const configDir = dirname(file) return esm => { it(testInfo.it, () => { @@ -24,6 +29,13 @@ return expected.to.be.rejectedWith(testInfo.err) } + if (testInfo.res instanceof RegExp) { + return expected + .to.be.fulfilled + .and.to.eventually.be.a('string') + .that.match(testInfo.res) + } + return expected .to.be.fulfilled .and.to.eventually.be.deep.equal(testInfo.res ?? undefined) @@ -63,7 +75,7 @@ const manualTests = esm => { it('should load the "config" folder by default', async () => { const configIO = await loadConfig(esm) - const yaml = YAML.parse(await readFile(join(__dirname, 'config/base.res.yaml'), 'utf8')) + const yaml = parseYamlFile('config/base.res.yaml') expect(configIO) .that.has.ownProperty('base') .that.is.deep.equal(yaml) diff --git a/test/tags/cmdline-option/1-no-seq/default.yaml b/test/tags/cmdline-option/1-no-seq/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uLzEtbm8tc2VxL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/1-no-seq/default.yaml @@ -0,0 +1,2 @@ +opt: !cmdline-option +- throws diff --git a/test/tags/cmdline-option/1-no-seq/test.spec.yaml b/test/tags/cmdline-option/1-no-seq/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uLzEtbm8tc2VxL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/1-no-seq/test.spec.yaml @@ -0,0 +1,4 @@ +it: should not be possible to construct from a sequence +start: + simpleMode: true +err: Can not be constructed from a sequence diff --git a/test/tags/cmdline-option/2-inspect/default.yaml b/test/tags/cmdline-option/2-inspect/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uLzItaW5zcGVjdC9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/cmdline-option/2-inspect/default.yaml @@ -0,0 +1,1 @@ +opt: !cmdline-option option diff --git a/test/tags/cmdline-option/2-inspect/test.spec.yaml b/test/tags/cmdline-option/2-inspect/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uLzItaW5zcGVjdC90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/2-inspect/test.spec.yaml @@ -0,0 +1,6 @@ +it: inspect should return a string explicting how the value was constructed +start: + simpleMode: true +mode: inspect +res: >- + { opt: CmdlineOption(option=undefined) } diff --git a/test/tags/cmdline-option/map form/1-not-provided/default.yaml b/test/tags/cmdline-option/map form/1-not-provided/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL21hcCBmb3JtLzEtbm90LXByb3ZpZGVkL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/map form/1-not-provided/default.yaml @@ -0,0 +1,2 @@ +opt: !cmdline-option + name: option diff --git a/test/tags/cmdline-option/map form/1-not-provided/test.spec.yaml b/test/tags/cmdline-option/map form/1-not-provided/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL21hcCBmb3JtLzEtbm90LXByb3ZpZGVkL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/map form/1-not-provided/test.spec.yaml @@ -0,0 +1,5 @@ +it: should accept a name key as an option name and return undefined if not provided +start: + simpleMode: true +property: opt +res: null diff --git a/test/tags/cmdline-option/map form/2-string/default.yaml b/test/tags/cmdline-option/map form/2-string/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL21hcCBmb3JtLzItc3RyaW5nL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/map form/2-string/default.yaml @@ -0,0 +1,2 @@ +opt: !cmdline-option + name: option diff --git a/test/tags/cmdline-option/map form/2-string/test.spec.yaml b/test/tags/cmdline-option/map form/2-string/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL21hcCBmb3JtLzItc3RyaW5nL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/map form/2-string/test.spec.yaml @@ -0,0 +1,8 @@ +it: should return option value as a string +start: + simpleMode: true +argv: +- --option +- option value +property: opt +res: option value diff --git a/test/tags/cmdline-option/map form/3-options/default.yaml b/test/tags/cmdline-option/map form/3-options/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL21hcCBmb3JtLzMtb3B0aW9ucy9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/cmdline-option/map form/3-options/default.yaml @@ -0,0 +1,4 @@ +opt: !cmdline-option + name: option + type: boolean + description: some description diff --git a/test/tags/cmdline-option/map form/3-options/test.spec.yaml b/test/tags/cmdline-option/map form/3-options/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL21hcCBmb3JtLzMtb3B0aW9ucy90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/map form/3-options/test.spec.yaml @@ -0,0 +1,6 @@ +it: should pass keys other than name to yargs +start: + simpleMode: true +mode: usage +usage: option +res: !regexp /^\s+--option\s+some description\s+\[boolean\]$/m diff --git a/test/tags/cmdline-option/map form/4-no-missing-name/default.yaml b/test/tags/cmdline-option/map form/4-no-missing-name/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL21hcCBmb3JtLzQtbm8tbWlzc2luZy1uYW1lL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/map form/4-no-missing-name/default.yaml @@ -0,0 +1,2 @@ +opt: !cmdline-option + description: option descr diff --git a/test/tags/cmdline-option/map form/4-no-missing-name/test.spec.yaml b/test/tags/cmdline-option/map form/4-no-missing-name/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL21hcCBmb3JtLzQtbm8tbWlzc2luZy1uYW1lL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/map form/4-no-missing-name/test.spec.yaml @@ -0,0 +1,4 @@ +it: should not accept to be constructed with a missing name +start: + simpleMode: true +err: '"name" is required' diff --git a/test/tags/cmdline-option/scalar form/1-not-provided/default.yaml b/test/tags/cmdline-option/scalar form/1-not-provided/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzEtbm90LXByb3ZpZGVkL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/scalar form/1-not-provided/default.yaml @@ -0,0 +1,1 @@ +opt: !cmdline-option option diff --git a/test/tags/cmdline-option/scalar form/1-not-provided/test.spec.yaml b/test/tags/cmdline-option/scalar form/1-not-provided/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzEtbm90LXByb3ZpZGVkL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/scalar form/1-not-provided/test.spec.yaml @@ -0,0 +1,5 @@ +it: should accept a string as an option name and return undefined if not provided +start: + simpleMode: true +property: opt +res: null diff --git a/test/tags/cmdline-option/scalar form/2-string/default.yaml b/test/tags/cmdline-option/scalar form/2-string/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzItc3RyaW5nL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/scalar form/2-string/default.yaml @@ -0,0 +1,1 @@ +opt: !cmdline-option option diff --git a/test/tags/cmdline-option/scalar form/2-string/test.spec.yaml b/test/tags/cmdline-option/scalar form/2-string/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzItc3RyaW5nL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/scalar form/2-string/test.spec.yaml @@ -0,0 +1,8 @@ +it: should return option value as a string +start: + simpleMode: true +argv: +- --option +- option value +property: opt +res: option value diff --git a/test/tags/cmdline-option/scalar form/3-number/default.yaml b/test/tags/cmdline-option/scalar form/3-number/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzMtbnVtYmVyL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/scalar form/3-number/default.yaml @@ -0,0 +1,1 @@ +opt: !cmdline-option option diff --git a/test/tags/cmdline-option/scalar form/3-number/test.spec.yaml b/test/tags/cmdline-option/scalar form/3-number/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzMtbnVtYmVyL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/scalar form/3-number/test.spec.yaml @@ -0,0 +1,8 @@ +it: should return a number when option value looks like one +start: + simpleMode: true +argv: +- --option +- '42.42' +property: opt +res: 42.42 diff --git a/test/tags/cmdline-option/scalar form/4-bool-true/default.yaml b/test/tags/cmdline-option/scalar form/4-bool-true/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzQtYm9vbC10cnVlL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/scalar form/4-bool-true/default.yaml @@ -0,0 +1,1 @@ +opt: !cmdline-option option diff --git a/test/tags/cmdline-option/scalar form/4-bool-true/test.spec.yaml b/test/tags/cmdline-option/scalar form/4-bool-true/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzQtYm9vbC10cnVlL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/scalar form/4-bool-true/test.spec.yaml @@ -0,0 +1,7 @@ +it: should return true when option was provided without a value +start: + simpleMode: true +argv: +- --option +property: opt +res: true diff --git a/test/tags/cmdline-option/scalar form/5-bool-false/default.yaml b/test/tags/cmdline-option/scalar form/5-bool-false/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzUtYm9vbC1mYWxzZS9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/cmdline-option/scalar form/5-bool-false/default.yaml @@ -0,0 +1,1 @@ +opt: !cmdline-option option diff --git a/test/tags/cmdline-option/scalar form/5-bool-false/test.spec.yaml b/test/tags/cmdline-option/scalar form/5-bool-false/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzUtYm9vbC1mYWxzZS90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/scalar form/5-bool-false/test.spec.yaml @@ -0,0 +1,7 @@ +it: should return false when option was provided prefixed with "no-" +start: + simpleMode: true +argv: +- --no-option +property: opt +res: false diff --git a/test/tags/cmdline-option/scalar form/6-no-missing-name/default.yaml b/test/tags/cmdline-option/scalar form/6-no-missing-name/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzYtbm8tbWlzc2luZy1uYW1lL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/scalar form/6-no-missing-name/default.yaml @@ -0,0 +1,1 @@ +opt: !cmdline-option diff --git a/test/tags/cmdline-option/scalar form/6-no-missing-name/test.spec.yaml b/test/tags/cmdline-option/scalar form/6-no-missing-name/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzYtbm8tbWlzc2luZy1uYW1lL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/cmdline-option/scalar form/6-no-missing-name/test.spec.yaml @@ -0,0 +1,4 @@ +it: should not accept to be constructed with a missing name +start: + simpleMode: true +err: '"name" is not allowed to be empty' diff --git a/test/tags/cmdline-option/scalar form/7-no-empty-name/default.yaml b/test/tags/cmdline-option/scalar form/7-no-empty-name/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzctbm8tZW1wdHktbmFtZS9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/cmdline-option/scalar form/7-no-empty-name/default.yaml @@ -0,0 +1,1 @@ +opt: !cmdline-option '' diff --git a/test/tags/cmdline-option/scalar form/7-no-empty-name/test.spec.yaml b/test/tags/cmdline-option/scalar form/7-no-empty-name/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2NtZGxpbmUtb3B0aW9uL3NjYWxhciBmb3JtLzctbm8tZW1wdHktbmFtZS90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/cmdline-option/scalar form/7-no-empty-name/test.spec.yaml @@ -0,0 +1,4 @@ +it: should not accept to be constructed with null as a name +start: + simpleMode: true +err: '"name" is not allowed to be empty' diff --git a/test/tags/fallback/3-null/default.yaml b/test/tags/fallback/3-null/default.yaml index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_dGVzdC90YWdzL2ZhbGxiYWNrLzMtbnVsbC9kZWZhdWx0LnlhbWw=..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2ZhbGxiYWNrLzMtbnVsbC9kZWZhdWx0LnlhbWw= 100644 --- a/test/tags/fallback/3-null/default.yaml +++ b/test/tags/fallback/3-null/default.yaml @@ -1,2 +1,3 @@ fallback: !fallback - +- null diff --git a/test/tags/fallback/9-no-empty/default.yaml b/test/tags/fallback/9-no-empty/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2ZhbGxiYWNrLzktbm8tZW1wdHkvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/fallback/9-no-empty/default.yaml @@ -0,0 +1,1 @@ +fallback: !fallback [] diff --git a/test/tags/fallback/9-no-empty/test.spec.yaml b/test/tags/fallback/9-no-empty/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC90YWdzL2ZhbGxiYWNrLzktbm8tZW1wdHkvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/fallback/9-no-empty/test.spec.yaml @@ -0,0 +1,4 @@ +it: should not be possible to construct from an empty sequence +start: + simpleMode: true +err: '"value" must contain at least 1 items' diff --git a/test/worker/load-worker.js b/test/worker/load-worker.js index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_dGVzdC93b3JrZXIvbG9hZC13b3JrZXIuanM=..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC93b3JrZXIvbG9hZC13b3JrZXIuanM= 100644 --- a/test/worker/load-worker.js +++ b/test/worker/load-worker.js @@ -1,3 +1,4 @@ const runTest = require('./run-test') +const { workerData } = require('worker_threads') // make argv look like a normal call even if mocha is used @@ -2,6 +3,6 @@ // make argv look like a normal call even if mocha is used -process.argv = ['node', __filename] +process.argv = ['node', __filename, ...((workerData || {}).argv || [])] // prevent debug messages from being displayed // TODO: fix this later on diff --git a/test/worker/load-worker.mjs b/test/worker/load-worker.mjs index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_dGVzdC93b3JrZXIvbG9hZC13b3JrZXIubWpz..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC93b3JrZXIvbG9hZC13b3JrZXIubWpz 100644 --- a/test/worker/load-worker.mjs +++ b/test/worker/load-worker.mjs @@ -1,5 +1,6 @@ import { fileURLToPath } from 'url' +import { workerData } from 'worker_threads' import runTest from './run-test.js' // make argv look like a normal call even if mocha is used @@ -2,8 +3,8 @@ import runTest from './run-test.js' // make argv look like a normal call even if mocha is used -process.argv = ['node', fileURLToPath(import.meta.url)] +process.argv = ['node', fileURLToPath(import.meta.url), ...((workerData || {}).argv || [])] // prevent debug messages from being displayed // TODO: fix this later on diff --git a/test/worker/run-test.js b/test/worker/run-test.js index 8352bc079b71bd3f01f7e7b449f02c304b9a7867_dGVzdC93b3JrZXIvcnVuLXRlc3QuanM=..111e3912dab959d10f9fcca3dec3e39bb3b5dc16_dGVzdC93b3JrZXIvcnVuLXRlc3QuanM= 100644 --- a/test/worker/run-test.js +++ b/test/worker/run-test.js @@ -30,6 +30,9 @@ case 'inspect': data = require('util').inspect(data) break + case 'usage': + require('yargs').showHelp(usage => (data = usage.match(new RegExp(`^\\s*--?${workerData.usage}.+$`, 'm'))[0])) + break default: data = _.cloneDeep(data) break