From d2e6a8adef5632ddf63581cfacc7cb77bbc634af Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 1 Mar 2021 16:57:14 +0100 Subject: [PATCH] fix(Variables): Resolve plain text for unrecognized extensions --- lib/configuration/variables/sources/file.js | 6 ++---- .../lib/configuration/variables/sources/file.test.js | 10 ++++++---- .../variables/sources/fixture/invalid.ext | 1 - .../variables/sources/fixture/non-standard.ext | 1 + 4 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 test/unit/lib/configuration/variables/sources/fixture/invalid.ext create mode 100644 test/unit/lib/configuration/variables/sources/fixture/non-standard.ext diff --git a/lib/configuration/variables/sources/file.js b/lib/configuration/variables/sources/file.js index b27b19ab6..8cbcc14b2 100644 --- a/lib/configuration/variables/sources/file.js +++ b/lib/configuration/variables/sources/file.js @@ -134,10 +134,8 @@ module.exports = { } } default: - throw new ServerlessError( - `Cannot parse "${path.basename(filePath)}": Unsupported file extension`, - 'UNSUPPORTED_FILE_TYPE' - ); + // Anything else support as plain text + return readFile(filePath); } })(); diff --git a/test/unit/lib/configuration/variables/sources/file.test.js b/test/unit/lib/configuration/variables/sources/file.test.js index bb34185d9..ef43df7de 100644 --- a/test/unit/lib/configuration/variables/sources/file.test.js +++ b/test/unit/lib/configuration/variables/sources/file.test.js @@ -41,7 +41,7 @@ describe('test/unit/lib/configuration/variables/sources/file.test.js', () => { invalidJson: '${file(invalid.json)}', invalidJs: '${file(invalid.js)}', invalidJs2: '${file(invalid2.js)}', - invalidExt: '${file(invalid.ext)}', + nonStandardExt: '${file(non-standard.ext)}', }; variablesMeta = resolveMeta(configuration); await resolve({ @@ -86,6 +86,11 @@ describe('test/unit/lib/configuration/variables/sources/file.test.js', () => { it('should report with null non existing JS files', () => expect(configuration.nonExistingJs).to.equal(null)); + it('should resolve plain text content on unrecognized extension', () => + // .trim() as depending on local .git settings and OS (Windows or other) + // checked out fixture may end with differen type of EOL (\n on linux, and \r\n on Windows) + expect(configuration.nonStandardExt.trim()).to.equal('result: non-standard'.trim())); + it('should report with an error address argument on primitive content', () => expect(variablesMeta.get('primitiveAddress').error.code).to.equal('VARIABLE_RESOLUTION_ERROR')); @@ -141,9 +146,6 @@ describe('test/unit/lib/configuration/variables/sources/file.test.js', () => { expect(variablesMeta.get('invalidJs2').error.code).to.equal('VARIABLE_RESOLUTION_ERROR'); }); - it('should report with an error an unrecognized extension', () => - expect(variablesMeta.get('invalidExt').error.code).to.equal('VARIABLE_RESOLUTION_ERROR')); - it('should not support function resolvers in "js" file sources not confirmed to work with new resolver', async () => { configuration = { jsFunction: '${file(file-function.js)}', diff --git a/test/unit/lib/configuration/variables/sources/fixture/invalid.ext b/test/unit/lib/configuration/variables/sources/fixture/invalid.ext deleted file mode 100644 index 6a3cdf440..000000000 --- a/test/unit/lib/configuration/variables/sources/fixture/invalid.ext +++ /dev/null @@ -1 +0,0 @@ -result: yml diff --git a/test/unit/lib/configuration/variables/sources/fixture/non-standard.ext b/test/unit/lib/configuration/variables/sources/fixture/non-standard.ext new file mode 100644 index 000000000..ddd3fe0f3 --- /dev/null +++ b/test/unit/lib/configuration/variables/sources/fixture/non-standard.ext @@ -0,0 +1 @@ +result: non-standard