mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed test on Node 20
refs f39d1d3aa3
- similar to the commit above, the JSON parser changed between Node 18
and Node 20, so the error message changed too
- we actually just want to check the error is forwarded to the user, so
we can do that by getting the error message from JSON.parse and check
against that
This commit is contained in:
parent
96adb0a5d8
commit
8e0ad1a6fb
1 changed files with 16 additions and 2 deletions
|
@ -95,15 +95,29 @@ describe('UNIT: redirects CustomRedirectsAPI class', function () {
|
|||
|
||||
describe('setFromFilePath', function () {
|
||||
it('throws a syntax error when setting invalid JSON redirects file', async function () {
|
||||
const invalidJSON = '{invalid json';
|
||||
const invalidFilePath = path.join(__dirname, '/invalid/redirects/path.json');
|
||||
fs.readFile.withArgs(invalidFilePath, 'utf-8').resolves('{invalid json');
|
||||
fs.readFile.withArgs(invalidFilePath, 'utf-8').resolves(invalidJSON);
|
||||
|
||||
let expectedErrorMessage;
|
||||
|
||||
try {
|
||||
JSON.parse(invalidJSON);
|
||||
} catch (err) {
|
||||
expectedErrorMessage = err.message;
|
||||
}
|
||||
|
||||
if (!expectedErrorMessage) {
|
||||
// This should never happen because the JSON is invalid
|
||||
should.fail('expectedErrorMessage is not set');
|
||||
}
|
||||
|
||||
try {
|
||||
await customRedirectsAPI.setFromFilePath(invalidFilePath, '.json');
|
||||
should.fail('setFromFilePath did not throw');
|
||||
} catch (err) {
|
||||
should.exist(err);
|
||||
err.message.should.eql('Could not parse JSON: Unexpected token i in JSON at position 1.');
|
||||
err.message.should.eql(`Could not parse JSON: ${expectedErrorMessage}.`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue