fix(Variables): Resolve plain text for unrecognized extensions

This commit is contained in:
Mariusz Nowak 2021-03-01 16:57:14 +01:00 committed by Mariusz Nowak
parent 131516a6d0
commit d2e6a8adef
4 changed files with 9 additions and 9 deletions

View File

@ -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);
}
})();

View File

@ -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)}',

View File

@ -0,0 +1 @@
result: non-standard