From ae75d52aafdfdd4dea4483083400c2d978bd5f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Z=C3=B6rb?= Date: Thu, 15 Aug 2024 00:13:12 +0200 Subject: [PATCH] Parse CLI args passed as JSON (#596) --- index.js | 2 +- package-lock.json | 130 ++++++++++++++++++++++++-------------------- package.json | 17 +++--- src/config.js | 20 ++++++- test/config.test.js | 63 +++++++++++---------- 5 files changed, 135 insertions(+), 97 deletions(-) diff --git a/index.js b/index.js index 25234925..1fa0fbed 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ import {getOptions} from './src/config.js'; */ export async function generate(params, cb) { try { - const options = getOptions(params); + const options = await getOptions(params); const {target = {}, base = process.cwd()} = options; const result = await create(options); // Store generated css diff --git a/package-lock.json b/package-lock.json index 5c0b4dd7..f45108c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,21 +9,22 @@ "version": "7.1.2", "license": "Apache-2.0", "dependencies": { - "@adobe/css-tools": "^4.3.3", + "@adobe/css-tools": "^4.4.0", + "async-traverse-tree": "^1.1.0", "clean-css": "^5.3.3", "common-tags": "^1.8.2", - "css-url-parser": "^1.1.3", - "data-uri-to-buffer": "^6.0.1", - "debug": "^4.3.4", + "css-url-parser": "^1.1.4", + "data-uri-to-buffer": "^6.0.2", + "debug": "^4.3.6", "find-up": "^7.0.0", "get-stdin": "^9.0.0", - "globby": "^14.0.1", + "globby": "^14.0.2", "got": "^13.0.0", "group-args": "^0.1.0", "indent-string": "^5.0.0", "inline-critical": "^12.0.1", "is-glob": "^4.0.3", - "joi": "^17.12.2", + "joi": "^17.13.3", "lodash": "^4.17.21", "lodash-es": "^4.17.21", "make-dir": "^4.0.0", @@ -31,9 +32,9 @@ "oust": "^2.0.4", "p-all": "^5.0.0", "penthouse": "^2.3.3", - "picocolors": "^1.0.0", + "picocolors": "^1.0.1", "plugin-error": "^2.0.1", - "postcss": "^8.4.38", + "postcss": "^8.4.41", "postcss-discard": "^2.0.0", "postcss-image-inliner": "^7.0.1", "postcss-url": "^10.1.3", @@ -74,9 +75,9 @@ } }, "node_modules/@adobe/css-tools": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.3.3.tgz", - "integrity": "sha512-rE0Pygv0sEZ4vBWHlAgJLGDU7Pm8xoO6p3wsEceb7GYAjScrOHpEo8KK/eVkAcnSM+slAEtXjA2JpdjLp4fJQQ==" + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.0.tgz", + "integrity": "sha512-Ff9+ksdQQB3rMncgqDK78uLznstjyfIf2Arnh22pW8kBpLs6rpKDwgnZT46hin5Hl1WzazzK64DOrhSwYpS7bQ==" }, "node_modules/@ampproject/remapping": { "version": "2.2.1", @@ -2948,6 +2949,14 @@ "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" }, + "node_modules/async-traverse-tree": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/async-traverse-tree/-/async-traverse-tree-1.1.0.tgz", + "integrity": "sha512-T5djGloPIHzq6fyK7FY5x4ei6ovCkIdqHXx6FSAwXby3MXxfHi6BU3EETU/IUYDXcJO4CCmsppZe+nuq9qc/Bw==", + "engines": { + "node": ">=16" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -3875,9 +3884,9 @@ } }, "node_modules/css-url-parser": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/css-url-parser/-/css-url-parser-1.1.3.tgz", - "integrity": "sha512-KO4HrqK3lAlrnobbBEHib/lFRw7kGOlQTLYhwTwWzDEGilGTYIYOpI22d+6euyZiqfZpV96pii87ZufifbxpqA==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/css-url-parser/-/css-url-parser-1.1.4.tgz", + "integrity": "sha512-gIpYB7ZqfIsd+/kJ8CE4pesAbIUEaZM+30Ylfl7rr0zJONslIchmi3utzY64qHIOhD/wXDrcSo7jU2VDqG7GiQ==" }, "node_modules/css-what": { "version": "6.1.0", @@ -3937,9 +3946,9 @@ "integrity": "sha512-d4ZVpCW31eWwCMe1YT3ur7mUDnTXbgwyzaL320DrcRT45rfjYxkt5QWLrmOJ+/UEAI2+fQgKe/fCjR8l4TpRgw==" }, "node_modules/data-uri-to-buffer": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.1.tgz", - "integrity": "sha512-MZd3VlchQkp8rdend6vrx7MmVDJzSNTBvghvKjirLkD+WTChA3KUf0jkE68Q4UyctNqI11zZO9/x2Yx+ub5Cvg==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz", + "integrity": "sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==", "engines": { "node": ">= 14" } @@ -4008,9 +4017,9 @@ } }, "node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", "dependencies": { "ms": "2.1.2" }, @@ -6191,9 +6200,9 @@ } }, "node_modules/globby": { - "version": "14.0.1", - "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.1.tgz", - "integrity": "sha512-jOMLD2Z7MAhyG8aJpNOpmziMOP4rPLcc95oQPKXBazW82z+CEgPFBQvEpRUa1KeIMUJo4Wsm+q6uzO/Q/4BksQ==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.2.tgz", + "integrity": "sha512-s3Fq41ZVh7vbbe2PN3nrW7yC7U7MFVc5c98/iTl9c2GawNMKx/J648KQRW6WKkuU8GIbbh2IXfIRQjOZnXcTnw==", "dependencies": { "@sindresorhus/merge-streams": "^2.1.0", "fast-glob": "^3.3.2", @@ -8498,9 +8507,9 @@ } }, "node_modules/joi": { - "version": "17.12.2", - "resolved": "https://registry.npmjs.org/joi/-/joi-17.12.2.tgz", - "integrity": "sha512-RonXAIzCiHLc8ss3Ibuz45u28GOsWE1UpfDXLbN/9NKbL4tCJf8TWYVKsoYuuh+sAUt7fsSNpA+r2+TBA6Wjmw==", + "version": "17.13.3", + "resolved": "https://registry.npmjs.org/joi/-/joi-17.13.3.tgz", + "integrity": "sha512-otDA4ldcIx+ZXsKHWmp0YizCweVRZG96J10b0FevjfuncLO1oX59THoAmHkNubYJ+9gWsYsp5k8v4ib6oDv1fA==", "dependencies": { "@hapi/hoek": "^9.3.0", "@hapi/topo": "^5.1.0", @@ -9546,9 +9555,9 @@ } }, "node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", + "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==" }, "node_modules/picomatch": { "version": "2.3.1", @@ -9688,9 +9697,9 @@ } }, "node_modules/postcss": { - "version": "8.4.38", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.38.tgz", - "integrity": "sha512-Wglpdk03BSfXkHoQa3b/oulrotAkwrlLDRSOb9D0bN86FdRyE9lppSp33aHNPgBa0JKCoB+drFLZkQoRRYae5A==", + "version": "8.4.41", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.41.tgz", + "integrity": "sha512-TesUflQ0WKZqAvg52PWL6kHgLKP6xB6heTOdoYM0Wt2UHyxNa4K25EZZMgKns3BH1RLVbZCREPpLY0rhnNoHVQ==", "funding": [ { "type": "opencollective", @@ -9707,7 +9716,7 @@ ], "dependencies": { "nanoid": "^3.3.7", - "picocolors": "^1.0.0", + "picocolors": "^1.0.1", "source-map-js": "^1.2.0" }, "engines": { @@ -12448,9 +12457,9 @@ "dev": true }, "@adobe/css-tools": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.3.3.tgz", - "integrity": "sha512-rE0Pygv0sEZ4vBWHlAgJLGDU7Pm8xoO6p3wsEceb7GYAjScrOHpEo8KK/eVkAcnSM+slAEtXjA2JpdjLp4fJQQ==" + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.0.tgz", + "integrity": "sha512-Ff9+ksdQQB3rMncgqDK78uLznstjyfIf2Arnh22pW8kBpLs6rpKDwgnZT46hin5Hl1WzazzK64DOrhSwYpS7bQ==" }, "@ampproject/remapping": { "version": "2.2.1", @@ -14628,6 +14637,11 @@ "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" }, + "async-traverse-tree": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/async-traverse-tree/-/async-traverse-tree-1.1.0.tgz", + "integrity": "sha512-T5djGloPIHzq6fyK7FY5x4ei6ovCkIdqHXx6FSAwXby3MXxfHi6BU3EETU/IUYDXcJO4CCmsppZe+nuq9qc/Bw==" + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -15305,9 +15319,9 @@ } }, "css-url-parser": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/css-url-parser/-/css-url-parser-1.1.3.tgz", - "integrity": "sha512-KO4HrqK3lAlrnobbBEHib/lFRw7kGOlQTLYhwTwWzDEGilGTYIYOpI22d+6euyZiqfZpV96pii87ZufifbxpqA==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/css-url-parser/-/css-url-parser-1.1.4.tgz", + "integrity": "sha512-gIpYB7ZqfIsd+/kJ8CE4pesAbIUEaZM+30Ylfl7rr0zJONslIchmi3utzY64qHIOhD/wXDrcSo7jU2VDqG7GiQ==" }, "css-what": { "version": "6.1.0", @@ -15352,9 +15366,9 @@ "integrity": "sha512-d4ZVpCW31eWwCMe1YT3ur7mUDnTXbgwyzaL320DrcRT45rfjYxkt5QWLrmOJ+/UEAI2+fQgKe/fCjR8l4TpRgw==" }, "data-uri-to-buffer": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.1.tgz", - "integrity": "sha512-MZd3VlchQkp8rdend6vrx7MmVDJzSNTBvghvKjirLkD+WTChA3KUf0jkE68Q4UyctNqI11zZO9/x2Yx+ub5Cvg==" + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz", + "integrity": "sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==" }, "data-urls": { "version": "5.0.0", @@ -15399,9 +15413,9 @@ } }, "debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", "requires": { "ms": "2.1.2" }, @@ -16954,9 +16968,9 @@ } }, "globby": { - "version": "14.0.1", - "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.1.tgz", - "integrity": "sha512-jOMLD2Z7MAhyG8aJpNOpmziMOP4rPLcc95oQPKXBazW82z+CEgPFBQvEpRUa1KeIMUJo4Wsm+q6uzO/Q/4BksQ==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.2.tgz", + "integrity": "sha512-s3Fq41ZVh7vbbe2PN3nrW7yC7U7MFVc5c98/iTl9c2GawNMKx/J648KQRW6WKkuU8GIbbh2IXfIRQjOZnXcTnw==", "requires": { "@sindresorhus/merge-streams": "^2.1.0", "fast-glob": "^3.3.2", @@ -18626,9 +18640,9 @@ } }, "joi": { - "version": "17.12.2", - "resolved": "https://registry.npmjs.org/joi/-/joi-17.12.2.tgz", - "integrity": "sha512-RonXAIzCiHLc8ss3Ibuz45u28GOsWE1UpfDXLbN/9NKbL4tCJf8TWYVKsoYuuh+sAUt7fsSNpA+r2+TBA6Wjmw==", + "version": "17.13.3", + "resolved": "https://registry.npmjs.org/joi/-/joi-17.13.3.tgz", + "integrity": "sha512-otDA4ldcIx+ZXsKHWmp0YizCweVRZG96J10b0FevjfuncLO1oX59THoAmHkNubYJ+9gWsYsp5k8v4ib6oDv1fA==", "requires": { "@hapi/hoek": "^9.3.0", "@hapi/topo": "^5.1.0", @@ -19376,9 +19390,9 @@ } }, "picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", + "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==" }, "picomatch": { "version": "2.3.1", @@ -19475,12 +19489,12 @@ "dev": true }, "postcss": { - "version": "8.4.38", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.38.tgz", - "integrity": "sha512-Wglpdk03BSfXkHoQa3b/oulrotAkwrlLDRSOb9D0bN86FdRyE9lppSp33aHNPgBa0JKCoB+drFLZkQoRRYae5A==", + "version": "8.4.41", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.41.tgz", + "integrity": "sha512-TesUflQ0WKZqAvg52PWL6kHgLKP6xB6heTOdoYM0Wt2UHyxNa4K25EZZMgKns3BH1RLVbZCREPpLY0rhnNoHVQ==", "requires": { "nanoid": "^3.3.7", - "picocolors": "^1.0.0", + "picocolors": "^1.0.1", "source-map-js": "^1.2.0" } }, diff --git a/package.json b/package.json index c610fc84..e7ebdd99 100644 --- a/package.json +++ b/package.json @@ -32,21 +32,22 @@ "node": ">=18.18" }, "dependencies": { - "@adobe/css-tools": "^4.3.3", + "@adobe/css-tools": "^4.4.0", + "async-traverse-tree": "^1.1.0", "clean-css": "^5.3.3", "common-tags": "^1.8.2", - "css-url-parser": "^1.1.3", - "data-uri-to-buffer": "^6.0.1", - "debug": "^4.3.4", + "css-url-parser": "^1.1.4", + "data-uri-to-buffer": "^6.0.2", + "debug": "^4.3.6", "find-up": "^7.0.0", "get-stdin": "^9.0.0", - "globby": "^14.0.1", + "globby": "^14.0.2", "got": "^13.0.0", "group-args": "^0.1.0", "indent-string": "^5.0.0", "inline-critical": "^12.0.1", "is-glob": "^4.0.3", - "joi": "^17.12.2", + "joi": "^17.13.3", "lodash": "^4.17.21", "lodash-es": "^4.17.21", "make-dir": "^4.0.0", @@ -54,9 +55,9 @@ "oust": "^2.0.4", "p-all": "^5.0.0", "penthouse": "^2.3.3", - "picocolors": "^1.0.0", + "picocolors": "^1.0.1", "plugin-error": "^2.0.1", - "postcss": "^8.4.38", + "postcss": "^8.4.41", "postcss-discard": "^2.0.0", "postcss-image-inliner": "^7.0.1", "postcss-url": "^10.1.3", diff --git a/src/config.js b/src/config.js index d90ec605..1ed5503b 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,7 @@ import process from 'node:process'; import Joi from 'joi'; import debugBase from 'debug'; +import {traverse, STOP} from 'async-traverse-tree'; import {ConfigError} from './errors.js'; const debug = debugBase('critical:config'); @@ -75,8 +76,23 @@ const schema = Joi.object() .label('options') .xor('html', 'src'); -export function getOptions(options = {}) { - const {error, value} = schema.validate(options); +export async function getOptions(options = {}) { + const parsedOptions = await traverse(options, (key, value) => { + if (['css', 'html', 'src'].includes(key)) { + return STOP; + } + + if (typeof value === 'string') { + try { + return JSON.parse(value); + } catch {} + } + + return value; + }); + + const {error, value} = schema.validate(parsedOptions); + const {inline, dimensions, penthouse = {}, target, ignore} = value || {}; if (error) { diff --git a/test/config.test.js b/test/config.test.js index 1e1ce54c..fb1ed68d 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -2,31 +2,31 @@ import {ConfigError} from '../src/errors.js'; import {getOptions, DEFAULT} from '../src/config.js'; test('Throws ConfigError on invalid config', () => { - expect(() => { - getOptions({invalidParam: true}); - }).toThrow(ConfigError); + expect(async () => { + await getOptions({invalidParam: true}); + }).rejects.toThrow(ConfigError); }); -test('Throws ConfigError on missing param', () => { - expect(() => { - getOptions({}); - }).toThrow(ConfigError); +test('Throws ConfigError on missing param', async () => { + expect(async () => { + await getOptions({}); + }).rejects.toThrow(ConfigError); }); -test('Throws ConfigError when html & src are both set', () => { - expect(() => { - getOptions({html: '...', src: '...'}); - }).toThrow(ConfigError); +test('Throws ConfigError when html & src are both set', async () => { + expect(async () => { + await getOptions({html: '...', src: '...'}); + }).rejects.toThrow(ConfigError); }); -test('Throws ConfigError on empty required value', () => { - expect(() => { - getOptions({src: ''}); - }).toThrow(ConfigError); +test('Throws ConfigError on empty required value', async () => { + expect(async () => { + await getOptions({src: ''}); + }).rejects.toThrow(ConfigError); }); -test('Returns config object', () => { - const config = getOptions({src: '...'}); +test('Returns config object', async () => { + const config = await getOptions({src: '...'}); expect(config).toMatchObject({ src: '...', width: DEFAULT.width, @@ -47,27 +47,27 @@ test('Returns config object', () => { }); }); -test('Target config on passed string', () => { - expect(getOptions({src: '...', target: 'test.css'})).toHaveProperty('target', {css: 'test.css'}); - expect(getOptions({src: '...', target: 'test.html'})).toHaveProperty('target', {html: 'test.html'}); +test('Target config on passed string', async () => { + expect(await getOptions({src: '...', target: 'test.css'})).toHaveProperty('target', {css: 'test.css'}); + expect(await getOptions({src: '...', target: 'test.html'})).toHaveProperty('target', {html: 'test.html'}); }); -test('Inline config on passed boolean', () => { - expect(getOptions({src: '...', inline: true, base: 'BASE'})).toHaveProperty('inline', { +test('Inline config on passed boolean', async () => { + expect(await getOptions({src: '...', inline: true, base: 'BASE'})).toHaveProperty('inline', { basePath: 'BASE', strategy: 'media', }); }); -test('Inline config on passed object', () => { - expect(getOptions({src: '...', inline: {check: true}, base: 'BASE'})).toHaveProperty('inline', { +test('Inline config on passed object', async () => { + expect(await getOptions({src: '...', inline: {check: true}, base: 'BASE'})).toHaveProperty('inline', { basePath: 'BASE', check: true, }); }); -test('Penthouse config on passed object', () => { - expect(getOptions({src: '...', penthouse: {check: true}})).toHaveProperty('penthouse', { +test('Penthouse config on passed object', async () => { + expect(await getOptions({src: '...', penthouse: {check: true}})).toHaveProperty('penthouse', { forceInclude: DEFAULT.include, timeout: DEFAULT.timeout, maxEmbeddedBase64Length: DEFAULT.maxImageFileSize, @@ -75,10 +75,17 @@ test('Penthouse config on passed object', () => { }); }); -test('Ignore config on passed array', () => { - expect(getOptions({src: '...', ignore: ['@font-face']})).toHaveProperty('ignore', { +test('Ignore config on passed array', async () => { + expect(await getOptions({src: '...', ignore: ['@font-face']})).toHaveProperty('ignore', { atrule: ['@font-face'], rule: ['@font-face'], decl: ['@font-face'], }); }); + +test('Parses config values passed as JSON string', async () => { + const headers = {cookie: 'key=value'}; + expect(await getOptions({src: '...', request: {headers: JSON.stringify(headers)}})).toHaveProperty('request', { + headers, + }); +});