diff --git a/.hgignore b/.hgignore index b692da20a12995060330695cf803f9f7f6776b33_LmhnaWdub3Jl..62b91ac970038a92e2d53c1754ef537131edceef_LmhnaWdub3Jl 100644 --- a/.hgignore +++ b/.hgignore @@ -1,2 +1,5 @@ -syntax: glob +syntax: rootglob + +**/.chrome +**/.directory @@ -2,3 +5,13 @@ -.chrome/ +**/*.bulk +**/*.DS_Store +**/*.dump +**/*.log +**/*.orig + +.nyc_output/ + +commonjs/ +coverage/ +esm/ node_modules/ @@ -4,9 +17,3 @@ node_modules/ -*.bulk -*.log -dist*/ -.directory -*.orig -*.dump -*.DS_Store +test/package-lock.json tmp/ @@ -12,6 +19,1 @@ tmp/ -commonjs/ -esm/ -test/package-lock.json -coverage/ -.nyc_output/ diff --git a/src/tags/config.mjs b/src/tags/config.mjs index b692da20a12995060330695cf803f9f7f6776b33_c3JjL3RhZ3MvY29uZmlnLm1qcw==..62b91ac970038a92e2d53c1754ef537131edceef_c3JjL3RhZ3MvY29uZmlnLm1qcw== 100644 --- a/src/tags/config.mjs +++ b/src/tags/config.mjs @@ -21,6 +21,7 @@ () => this.exposeConfig(config), err => { err = new ConfigIOCustomTagError(cst, `Impossible to load config.io namespace ${ns}: ${err.message}`) + /* istanbul ignore else */ if (doc.options.prettyErrors) { err.makePretty() } diff --git a/src/tags/import.mjs b/src/tags/import.mjs index b692da20a12995060330695cf803f9f7f6776b33_c3JjL3RhZ3MvaW1wb3J0Lm1qcw==..62b91ac970038a92e2d53c1754ef537131edceef_c3JjL3RhZ3MvaW1wb3J0Lm1qcw== 100644 --- a/src/tags/import.mjs +++ b/src/tags/import.mjs @@ -4,6 +4,7 @@ import { createRequire } from 'module' import { inspect } from 'util' import { extname, resolve } from 'path' +import Joi from '@hapi/joi' import { readFileSync } from 'fs' import YAML from 'yaml' @@ -11,7 +12,7 @@ import { PRIVATE } from '../symbols.mjs' import { ConfigIOCustomTagError } from '../errors.mjs' -const internalRequire = createRequire?.(import.meta.url) || require +const internalRequire = createRequire?.(import.meta.url) || /* istanbul ignore next */ require class Import { static defaultOptions = { @@ -21,8 +22,12 @@ constructor (options, doc, cst) { this.baseDir = doc[PRIVATE].options.baseDir - this._options = options - this.options = Object.assign({}, Import.defaultOptions, options) + this.options = Joi.attempt(options, Joi.object({ + path: Joi.string().min(1).required(), + property: Joi.string().min(1), + throw: Joi.boolean().default(Import.defaultOptions.throw), + type: Joi.string().default(Import.defaultOptions.type), + })) const ext = extname(this.options.path) @@ -31,6 +36,6 @@ case '.js': switch (this.options.type) { case 'module': - this.loadESM(ext ? this.path : this.options.path, doc, cst) + this.loadESM(this.path, doc, cst) break case 'commonjs': @@ -35,6 +40,6 @@ break case 'commonjs': - this.loadCommonJS(ext ? this.path : this.options.path) + this.loadCommonJS(this.path) break default: throw new Error(`Unknown module type ${this.options.type}`) @@ -69,6 +74,7 @@ val => this.handleValue(val), err => { err = new ConfigIOCustomTagError(cst, `Impossible to load ESM module ${path}: ${err.message}`) + /* istanbul ignore else */ if (doc.options.prettyErrors) { err.makePretty() } @@ -92,8 +98,8 @@ this.value = _.get(this.value, this.options.property) } - if (this.value === undefined && this.options.throw) { - throw new Error('Import resolved to undefined!') + if ((this.value === undefined || this.value === null) && this.options.throw) { + throw new Error('Import resolved to null or undefined!') } } @@ -126,7 +132,13 @@ throw new Error('Cannot be constructed from a sequence.') }, toYAML (data) { - return Object.keys(data._options).length === 1 ? data._options.path : data._options + const exportedOptions = _.pickBy(data.options, (val, key) => { + if (val === undefined || val === null) { + return false + } + return val !== Import.defaultOptions[key] + }) + return Object.keys(exportedOptions).length === 1 ? exportedOptions.path : exportedOptions }, } } diff --git a/test/index.spec.js b/test/index.spec.js index b692da20a12995060330695cf803f9f7f6776b33_dGVzdC9pbmRleC5zcGVjLmpz..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC9pbmRleC5zcGVjLmpz 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -2,7 +2,5 @@ const chai = require('chai') const chaiAsPromised = require('chai-as-promised') const { dirname, join, resolve, sep } = require('path') -const { sync: glob } = require('glob') -const semver = require('semver') const { readFileSync } = require('fs') const { regexpTag } = require('../commonjs/tags/regexp') @@ -7,5 +5,7 @@ const { readFileSync } = require('fs') const { regexpTag } = require('../commonjs/tags/regexp') +const semver = require('semver') +const { sync: glob } = require('glob') const YAML = require('yaml') const expect = chai.expect @@ -25,7 +25,8 @@ if (testInfo.node && !semver.satisfies(process.version, testInfo.node)) { return } - it(testInfo.it, () => { + const localIt = testInfo.only ? it.only.bind(it) : it + localIt(testInfo.it, () => { let configPromise = loadConfig(esm, configDir, testInfo) if (testInfo.instanceof) { @@ -76,9 +77,53 @@ ) .value() -const yamlTests = createSubGroups( - glob('**/test.spec.yaml', { cwd: join(__dirname) }), -) +const compare = (a, b) => a < b + ? -1 + : (a === b ? 0 : 1) + +const NUMBERED_MATCH = /([0-9]+)(_|[^\w])+/ +const testFiles = glob('**/test.spec.yaml', { + cwd: join(__dirname), + nosort: true, +}) + .sort((a, b) => { + const splitA = a.split(sep) + const splitB = b.split(sep) + + for (const [idx, pathA] of splitA.entries()) { + if (idx > splitB.length) { + return -1 + } + const pathB = splitB[idx] + + if (pathA === pathB) { + continue + } + + const splitPathA = pathA.match(NUMBERED_MATCH) + const splitPathB = pathB.match(NUMBERED_MATCH) + + const nbA = Number(splitPathA && splitPathA[1]) + const nbB = Number(splitPathB && splitPathB[1]) + + if (!isNaN(nbA) && isNaN(nbB)) { + return -1 + } + if (isNaN(nbA) && !isNaN(nbB)) { + return 1 + } + + if (splitA.length <= 1 || isNaN(nbA)) { + return compare(pathA, pathB) + } + + return compare(nbA, nbB) + } + + return splitB.length > splitA.length ? 1 : 0 + }) + +const yamlTests = createSubGroups(testFiles) const setupAllTestsWith = (type, manualTests) => { describe(type, async () => { diff --git a/test/node_modules/config.io b/test/node_modules/config.io new file mode 120000 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC9ub2RlX21vZHVsZXMvY29uZmlnLmlv --- /dev/null +++ b/test/node_modules/config.io @@ -0,0 +1,1 @@ +../.. \ No newline at end of file diff --git a/test/tags/env/inspect/3-option-depth-null/test.spec.yaml b/test/tags/env/inspect/3-option-depth-null/test.spec.yaml index b692da20a12995060330695cf803f9f7f6776b33_dGVzdC90YWdzL2Vudi9pbnNwZWN0LzMtb3B0aW9uLWRlcHRoLW51bGwvdGVzdC5zcGVjLnlhbWw=..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2Vudi9pbnNwZWN0LzMtb3B0aW9uLWRlcHRoLW51bGwvdGVzdC5zcGVjLnlhbWw= 100644 --- a/test/tags/env/inspect/3-option-depth-null/test.spec.yaml +++ b/test/tags/env/inspect/3-option-depth-null/test.spec.yaml @@ -1,4 +1,4 @@ -it: inspect should return a string explicting how the value was constructed +it: inspect should work with depth null option start: simpleMode: true mode: inspect diff --git a/test/tags/fallback/inspect/2-option-depth-null/test.spec.yaml b/test/tags/fallback/inspect/2-option-depth-null/test.spec.yaml index b692da20a12995060330695cf803f9f7f6776b33_dGVzdC90YWdzL2ZhbGxiYWNrL2luc3BlY3QvMi1vcHRpb24tZGVwdGgtbnVsbC90ZXN0LnNwZWMueWFtbA==..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ZhbGxiYWNrL2luc3BlY3QvMi1vcHRpb24tZGVwdGgtbnVsbC90ZXN0LnNwZWMueWFtbA== 100644 --- a/test/tags/fallback/inspect/2-option-depth-null/test.spec.yaml +++ b/test/tags/fallback/inspect/2-option-depth-null/test.spec.yaml @@ -1,4 +1,4 @@ -it: inspect should return a string explicting how the value was constructed +it: inspect should work with depth null option start: simpleMode: true mode: inspect diff --git a/test/tags/import/base.cjs b/test/tags/import/base.cjs new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9iYXNlLmNqcw== --- /dev/null +++ b/test/tags/import/base.cjs @@ -0,0 +1,4 @@ +module.exports.value = { + number: 42, + null: null, +} diff --git a/test/tags/import/commonjs/1-basic/default.yaml b/test/tags/import/commonjs/1-basic/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy8xLWJhc2ljL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/import/commonjs/1-basic/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/base.cjs diff --git a/test/tags/import/commonjs/1-basic/test.spec.yaml b/test/tags/import/commonjs/1-basic/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy8xLWJhc2ljL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/import/commonjs/1-basic/test.spec.yaml @@ -0,0 +1,8 @@ +it: should load the cjs files +start: + simpleMode: true +property: import +res: + value: + number: 42 + 'null': null diff --git a/test/tags/import/commonjs/2-js-no-type/default.yaml b/test/tags/import/commonjs/2-js-no-type/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy8yLWpzLW5vLXR5cGUvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/commonjs/2-js-no-type/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/commonjs/base.js diff --git a/test/tags/import/commonjs/2-js-no-type/test.spec.yaml b/test/tags/import/commonjs/2-js-no-type/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy8yLWpzLW5vLXR5cGUvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/commonjs/2-js-no-type/test.spec.yaml @@ -0,0 +1,8 @@ +it: should show property in options +start: + simpleMode: true +property: import +res: + value: + number: 42 + 'null': null diff --git a/test/tags/import/commonjs/3-js-type-commonjs/default.yaml b/test/tags/import/commonjs/3-js-type-commonjs/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy8zLWpzLXR5cGUtY29tbW9uanMvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/commonjs/3-js-type-commonjs/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/commonjs/base.js + type: commonjs diff --git a/test/tags/import/commonjs/3-js-type-commonjs/test.spec.yaml b/test/tags/import/commonjs/3-js-type-commonjs/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy8zLWpzLXR5cGUtY29tbW9uanMvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/commonjs/3-js-type-commonjs/test.spec.yaml @@ -0,0 +1,8 @@ +it: should load the js files with type = "commonjs" +start: + simpleMode: true +property: import +res: + value: + number: 42 + 'null': null diff --git a/test/tags/import/commonjs/4-no-extension/default.yaml b/test/tags/import/commonjs/4-no-extension/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy80LW5vLWV4dGVuc2lvbi9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/commonjs/4-no-extension/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/commonjs/base + type: commonjs diff --git a/test/tags/import/commonjs/4-no-extension/test.spec.yaml b/test/tags/import/commonjs/4-no-extension/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy80LW5vLWV4dGVuc2lvbi90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/commonjs/4-no-extension/test.spec.yaml @@ -0,0 +1,8 @@ +it: should look for js files if no extension is provided +start: + simpleMode: true +property: import +res: + value: + number: 42 + 'null': null diff --git a/test/tags/import/commonjs/5-option-property/default.yaml b/test/tags/import/commonjs/5-option-property/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy81LW9wdGlvbi1wcm9wZXJ0eS9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/commonjs/5-option-property/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/base.cjs + property: value diff --git a/test/tags/import/commonjs/5-option-property/test.spec.yaml b/test/tags/import/commonjs/5-option-property/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy81LW9wdGlvbi1wcm9wZXJ0eS90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/commonjs/5-option-property/test.spec.yaml @@ -0,0 +1,7 @@ +it: should support the property option +start: + simpleMode: true +property: import +res: + number: 42 + 'null': null diff --git a/test/tags/import/commonjs/base.js b/test/tags/import/commonjs/base.js new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9jb21tb25qcy9iYXNlLmpz --- /dev/null +++ b/test/tags/import/commonjs/base.js @@ -0,0 +1,4 @@ +module.exports.value = { + number: 42, + null: null, +} diff --git a/test/tags/import/errors/1-no-seq/default.yaml b/test/tags/import/errors/1-no-seq/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMS1uby1zZXEvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/errors/1-no-seq/default.yaml @@ -0,0 +1,2 @@ +import: !import +- invalid diff --git a/test/tags/import/errors/1-no-seq/test.spec.yaml b/test/tags/import/errors/1-no-seq/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMS1uby1zZXEvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/errors/1-no-seq/test.spec.yaml @@ -0,0 +1,4 @@ +it: should not be possible to construct from a sequence +start: + simpleMode: true +err: Cannot be constructed from a sequence diff --git a/test/tags/import/errors/10-invalid-option/default.yaml b/test/tags/import/errors/10-invalid-option/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMTAtaW52YWxpZC1vcHRpb24vZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/errors/10-invalid-option/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/base.cjs + invalid: option diff --git a/test/tags/import/errors/10-invalid-option/test.spec.yaml b/test/tags/import/errors/10-invalid-option/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMTAtaW52YWxpZC1vcHRpb24vdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/errors/10-invalid-option/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when passing an invalid option +start: + simpleMode: true +err: '"invalid" is not allowed' diff --git a/test/tags/import/errors/11-no-null-path-scalar/default.yaml b/test/tags/import/errors/11-no-null-path-scalar/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMTEtbm8tbnVsbC1wYXRoLXNjYWxhci9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/errors/11-no-null-path-scalar/default.yaml @@ -0,0 +1,1 @@ +import: !import diff --git a/test/tags/import/errors/11-no-null-path-scalar/test.spec.yaml b/test/tags/import/errors/11-no-null-path-scalar/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMTEtbm8tbnVsbC1wYXRoLXNjYWxhci90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/errors/11-no-null-path-scalar/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when not giving any value to import in scalar form +start: + simpleMode: true +err: '"path" is not allowed to be empty' diff --git a/test/tags/import/errors/12-no-empty-path/default.yaml b/test/tags/import/errors/12-no-empty-path/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMTItbm8tZW1wdHktcGF0aC9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/errors/12-no-empty-path/default.yaml @@ -0,0 +1,2 @@ +import: !import + path: '' diff --git a/test/tags/import/errors/12-no-empty-path/test.spec.yaml b/test/tags/import/errors/12-no-empty-path/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMTItbm8tZW1wdHktcGF0aC90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/errors/12-no-empty-path/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when passing an empty string to path +start: + simpleMode: true +err: '"path" is not allowed to be empty' diff --git a/test/tags/import/errors/2-value-undefined/default.yaml b/test/tags/import/errors/2-value-undefined/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMi12YWx1ZS11bmRlZmluZWQvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/errors/2-value-undefined/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/base.cjs + property: value.undefined diff --git a/test/tags/import/errors/2-value-undefined/test.spec.yaml b/test/tags/import/errors/2-value-undefined/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMi12YWx1ZS11bmRlZmluZWQvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/errors/2-value-undefined/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when importing undefined without providing option throw to false +start: + simpleMode: true +err: Import resolved to null or undefined! diff --git a/test/tags/import/errors/3-value-null/default.yaml b/test/tags/import/errors/3-value-null/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMy12YWx1ZS1udWxsL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/import/errors/3-value-null/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/base.cjs + property: value.null diff --git a/test/tags/import/errors/3-value-null/test.spec.yaml b/test/tags/import/errors/3-value-null/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvMy12YWx1ZS1udWxsL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/import/errors/3-value-null/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when importing null without providing option throw to false +start: + simpleMode: true +err: Import resolved to null or undefined! diff --git a/test/tags/import/errors/4-load-js-unknown-type/default.yaml b/test/tags/import/errors/4-load-js-unknown-type/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvNC1sb2FkLWpzLXVua25vd24tdHlwZS9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/errors/4-load-js-unknown-type/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/base.js + type: unknown! diff --git a/test/tags/import/errors/4-load-js-unknown-type/test.spec.yaml b/test/tags/import/errors/4-load-js-unknown-type/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvNC1sb2FkLWpzLXVua25vd24tdHlwZS90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/errors/4-load-js-unknown-type/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when loading a js file with an invalid type option +start: + simpleMode: true +err: Unknown module type unknown! diff --git a/test/tags/import/errors/5-invalid-commonjs-path/default.yaml b/test/tags/import/errors/5-invalid-commonjs-path/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvNS1pbnZhbGlkLWNvbW1vbmpzLXBhdGgvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/errors/5-invalid-commonjs-path/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/nonexistent.js diff --git a/test/tags/import/errors/5-invalid-commonjs-path/test.spec.yaml b/test/tags/import/errors/5-invalid-commonjs-path/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvNS1pbnZhbGlkLWNvbW1vbmpzLXBhdGgvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/errors/5-invalid-commonjs-path/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when loading a commonjs file that does not exists! +start: + simpleMode: true +err: Cannot find module diff --git a/test/tags/import/errors/6-invalid-mjs-path/default.yaml b/test/tags/import/errors/6-invalid-mjs-path/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvNi1pbnZhbGlkLW1qcy1wYXRoL2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/import/errors/6-invalid-mjs-path/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/nonexistent.mjs diff --git a/test/tags/import/errors/6-invalid-mjs-path/test.spec.yaml b/test/tags/import/errors/6-invalid-mjs-path/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvNi1pbnZhbGlkLW1qcy1wYXRoL3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/import/errors/6-invalid-mjs-path/test.spec.yaml @@ -0,0 +1,7 @@ +node: '>=13.2.0' +it: should throw when loading an ESM file that does not exists! +start: + simpleMode: true + allowAsync: true +await: true +err: Cannot find module diff --git a/test/tags/import/errors/7-invalid-yaml-path/default.yaml b/test/tags/import/errors/7-invalid-yaml-path/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvNy1pbnZhbGlkLXlhbWwtcGF0aC9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/errors/7-invalid-yaml-path/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/nonexistent.yaml diff --git a/test/tags/import/errors/7-invalid-yaml-path/test.spec.yaml b/test/tags/import/errors/7-invalid-yaml-path/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvNy1pbnZhbGlkLXlhbWwtcGF0aC90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/errors/7-invalid-yaml-path/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when loading a yaml file that does not exists! +start: + simpleMode: true +err: 'ENOENT: no such file or directory, open' diff --git a/test/tags/import/errors/8-load-esm-without-ext/default.yaml b/test/tags/import/errors/8-load-esm-without-ext/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvOC1sb2FkLWVzbS13aXRob3V0LWV4dC9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/errors/8-load-esm-without-ext/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/esm/base + type: module diff --git a/test/tags/import/errors/8-load-esm-without-ext/test.spec.yaml b/test/tags/import/errors/8-load-esm-without-ext/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvOC1sb2FkLWVzbS13aXRob3V0LWV4dC90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/errors/8-load-esm-without-ext/test.spec.yaml @@ -0,0 +1,7 @@ +node: '>=13.2.0' +it: should throw when loading an ESM module without extension +start: + simpleMode: true + allowAsync: true +await: true +err: Cannot find module diff --git a/test/tags/import/errors/9-invalid-format/default.yaml b/test/tags/import/errors/9-invalid-format/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvOS1pbnZhbGlkLWZvcm1hdC9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/errors/9-invalid-format/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/esm/base.unknown diff --git a/test/tags/import/errors/9-invalid-format/test.spec.yaml b/test/tags/import/errors/9-invalid-format/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lcnJvcnMvOS1pbnZhbGlkLWZvcm1hdC90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/errors/9-invalid-format/test.spec.yaml @@ -0,0 +1,4 @@ +it: should throw when loading an unknown file type +start: + simpleMode: true +err: unknown format is not supported yet! diff --git a/test/tags/import/esm/1-basic/default.yaml b/test/tags/import/esm/1-basic/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vMS1iYXNpYy9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/esm/1-basic/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/esm/base.mjs diff --git a/test/tags/import/esm/1-basic/test.spec.yaml b/test/tags/import/esm/1-basic/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vMS1iYXNpYy90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/esm/1-basic/test.spec.yaml @@ -0,0 +1,10 @@ +node: '>=13.2.0' +it: should load the mjs files +start: + simpleMode: true + allowAsync: true +await: true +property: import.value +res: + number: 42 + 'null': null diff --git a/test/tags/import/esm/2-js-type-esm/default.yaml b/test/tags/import/esm/2-js-type-esm/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vMi1qcy10eXBlLWVzbS9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/esm/2-js-type-esm/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/esm/base.js + type: module diff --git a/test/tags/import/esm/2-js-type-esm/test.spec.yaml b/test/tags/import/esm/2-js-type-esm/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vMi1qcy10eXBlLWVzbS90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/esm/2-js-type-esm/test.spec.yaml @@ -0,0 +1,10 @@ +node: '>=13.2.0' +it: should load the js files with type = "module" +start: + simpleMode: true + allowAsync: true +await: true +property: import.value +res: + number: 42 + 'null': null diff --git a/test/tags/import/esm/3-option-property/default.yaml b/test/tags/import/esm/3-option-property/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vMy1vcHRpb24tcHJvcGVydHkvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/esm/3-option-property/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/esm/base.mjs + property: value diff --git a/test/tags/import/esm/3-option-property/test.spec.yaml b/test/tags/import/esm/3-option-property/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vMy1vcHRpb24tcHJvcGVydHkvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/esm/3-option-property/test.spec.yaml @@ -0,0 +1,10 @@ +node: '>=13.2.0' +it: should support the property option +start: + simpleMode: true + allowAsync: true +await: true +property: import +res: + number: 42 + 'null': null diff --git a/test/tags/import/esm/base.js b/test/tags/import/esm/base.js new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vYmFzZS5qcw== --- /dev/null +++ b/test/tags/import/esm/base.js @@ -0,0 +1,4 @@ +export const value = { + number: 42, + null: null, +} diff --git a/test/tags/import/esm/base.mjs b/test/tags/import/esm/base.mjs new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vYmFzZS5tanM= --- /dev/null +++ b/test/tags/import/esm/base.mjs @@ -0,0 +1,4 @@ +export const value = { + number: 42, + null: null, +} diff --git a/test/tags/import/esm/package.json b/test/tags/import/esm/package.json new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9lc20vcGFja2FnZS5qc29u --- /dev/null +++ b/test/tags/import/esm/package.json @@ -0,0 +1,1 @@ +{"type": "module"} diff --git a/test/tags/import/inspect/1-no-options/default.yaml b/test/tags/import/inspect/1-no-options/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9pbnNwZWN0LzEtbm8tb3B0aW9ucy9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/inspect/1-no-options/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/base.cjs diff --git a/test/tags/import/inspect/1-no-options/test.spec.yaml b/test/tags/import/inspect/1-no-options/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9pbnNwZWN0LzEtbm8tb3B0aW9ucy90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/inspect/1-no-options/test.spec.yaml @@ -0,0 +1,6 @@ +it: should return a string explicting how the value was constructed +start: + simpleMode: true +mode: inspect +res: >- + { import: Import(tags/import/base.cjs => { value: [Object] }) } diff --git a/test/tags/import/inspect/2-option-depth-null/default.yaml b/test/tags/import/inspect/2-option-depth-null/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9pbnNwZWN0LzItb3B0aW9uLWRlcHRoLW51bGwvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/inspect/2-option-depth-null/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/base.cjs diff --git a/test/tags/import/inspect/2-option-depth-null/test.spec.yaml b/test/tags/import/inspect/2-option-depth-null/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9pbnNwZWN0LzItb3B0aW9uLWRlcHRoLW51bGwvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/inspect/2-option-depth-null/test.spec.yaml @@ -0,0 +1,10 @@ +it: should work with depth null option +start: + simpleMode: true +mode: inspect +inspect: + depth: null +res: >- + { + import: Import(tags/import/base.cjs => { value: { number: 42, null: null } }) + } diff --git a/test/tags/import/inspect/3-property/default.yaml b/test/tags/import/inspect/3-property/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9pbnNwZWN0LzMtcHJvcGVydHkvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/inspect/3-property/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/base.cjs + property: value diff --git a/test/tags/import/inspect/3-property/test.spec.yaml b/test/tags/import/inspect/3-property/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9pbnNwZWN0LzMtcHJvcGVydHkvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/inspect/3-property/test.spec.yaml @@ -0,0 +1,8 @@ +it: should show the imported property when provided in options +start: + simpleMode: true +mode: inspect +res: >- + { + import: Import(tags/import/base.cjs[value] => { number: 42, null: null }) + } diff --git a/test/tags/import/json-and-yaml/1-basic/default.yaml b/test/tags/import/json-and-yaml/1-basic/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sLzEtYmFzaWMvZGVmYXVsdC55YW1s --- /dev/null +++ b/test/tags/import/json-and-yaml/1-basic/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/json-and-yaml/base.yaml diff --git a/test/tags/import/json-and-yaml/1-basic/test.spec.yaml b/test/tags/import/json-and-yaml/1-basic/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sLzEtYmFzaWMvdGVzdC5zcGVjLnlhbWw= --- /dev/null +++ b/test/tags/import/json-and-yaml/1-basic/test.spec.yaml @@ -0,0 +1,8 @@ +it: should load files with the yaml extension +start: + simpleMode: true +property: import +res: + value: + number: 42 + 'null': null diff --git a/test/tags/import/json-and-yaml/2-yml-ext/default.yaml b/test/tags/import/json-and-yaml/2-yml-ext/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sLzIteW1sLWV4dC9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/json-and-yaml/2-yml-ext/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/json-and-yaml/base.yml diff --git a/test/tags/import/json-and-yaml/2-yml-ext/test.spec.yaml b/test/tags/import/json-and-yaml/2-yml-ext/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sLzIteW1sLWV4dC90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/json-and-yaml/2-yml-ext/test.spec.yaml @@ -0,0 +1,8 @@ +it: should load the files with the yml extension +start: + simpleMode: true +property: import +res: + value: + number: 42 + 'null': null diff --git a/test/tags/import/json-and-yaml/3-json/default.yaml b/test/tags/import/json-and-yaml/3-json/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sLzMtanNvbi9kZWZhdWx0LnlhbWw= --- /dev/null +++ b/test/tags/import/json-and-yaml/3-json/default.yaml @@ -0,0 +1,1 @@ +import: !import tags/import/json-and-yaml/base.json diff --git a/test/tags/import/json-and-yaml/3-json/test.spec.yaml b/test/tags/import/json-and-yaml/3-json/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sLzMtanNvbi90ZXN0LnNwZWMueWFtbA== --- /dev/null +++ b/test/tags/import/json-and-yaml/3-json/test.spec.yaml @@ -0,0 +1,8 @@ +it: should load the files with the json extension +start: + simpleMode: true +property: import +res: + value: + number: 42 + 'null': null diff --git a/test/tags/import/json-and-yaml/4-option-property/default.yaml b/test/tags/import/json-and-yaml/4-option-property/default.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sLzQtb3B0aW9uLXByb3BlcnR5L2RlZmF1bHQueWFtbA== --- /dev/null +++ b/test/tags/import/json-and-yaml/4-option-property/default.yaml @@ -0,0 +1,3 @@ +import: !import + path: tags/import/json-and-yaml/base.yaml + property: value diff --git a/test/tags/import/json-and-yaml/4-option-property/test.spec.yaml b/test/tags/import/json-and-yaml/4-option-property/test.spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sLzQtb3B0aW9uLXByb3BlcnR5L3Rlc3Quc3BlYy55YW1s --- /dev/null +++ b/test/tags/import/json-and-yaml/4-option-property/test.spec.yaml @@ -0,0 +1,7 @@ +it: should support the property option +start: + simpleMode: true +property: import +res: + number: 42 + 'null': null diff --git a/test/tags/import/json-and-yaml/base.json b/test/tags/import/json-and-yaml/base.json new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sL2Jhc2UuanNvbg== --- /dev/null +++ b/test/tags/import/json-and-yaml/base.json @@ -0,0 +1,6 @@ +{ + "value": { + "number": 42, + "null": null + } +} diff --git a/test/tags/import/json-and-yaml/base.yaml b/test/tags/import/json-and-yaml/base.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sL2Jhc2UueWFtbA== --- /dev/null +++ b/test/tags/import/json-and-yaml/base.yaml @@ -0,0 +1,3 @@ +value: + number: 42 + 'null': null diff --git a/test/tags/import/json-and-yaml/base.yml b/test/tags/import/json-and-yaml/base.yml new file mode 100644 index 0000000000000000000000000000000000000000..62b91ac970038a92e2d53c1754ef537131edceef_dGVzdC90YWdzL2ltcG9ydC9qc29uLWFuZC15YW1sL2Jhc2UueW1s --- /dev/null +++ b/test/tags/import/json-and-yaml/base.yml @@ -0,0 +1,3 @@ +value: + number: 42 + 'null': null