APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
952 stars 227 forks source link

ubuntu invalid json test failing #289

Closed philsturgeon closed 6 months ago

philsturgeon commented 1 year ago

Release is blocked by this failing test on ubuntu.

   1) Invalid syntax
       in main file
         when continueOnError is true
           should throw a grouped error for an invalid JSON file with YAML disabled:

      AssertionError: expected [ Array(1) ] to contain subset [ Array(1) ]
      + expected - actual

       [
      -  "ParserError: Error parsing /home/runner/work/json-schema-ref-parser/json-schema-ref-parser/test/specs/invalid/invalid.json: Expected property name or '}' in JSON at position 2"
      +  {
      +    "message": [Function]
      +    "name": "ParserError"
      +    "path": []
      +    "source": [Function]
      +  }
       ]

      at Context.<anonymous> (test/specs/invalid/invalid.spec.js:159:33)

This test looks like its expecting a particular error object format for expect(err.errors).to.containSubset([ which is simply not there on ubuntu.

it("should throw a grouped error for an invalid JSON file with YAML disabled", async () => {
        const parser = new $RefParser();
        try {
          await parser.dereference(path.rel("specs/invalid/invalid.json"), { continueOnError: true, parse: { yaml: false }});
          helper.shouldNotGetCalled();
        }
        catch (err) {
          expect(err).to.be.instanceof(JSONParserErrorGroup);
          expect(err.files).to.equal(parser);
          expect(err.message).to.equal(`1 error occurred while reading '${path.abs("specs/invalid/invalid.json")}'`);
          expect(err.errors.length).to.equal(1);
          expect(err.errors).to.containSubset([
            {
              name: ParserError.name,
              message: message => (
                message.includes("invalid.json: Unexpected end of JSON input") ||
                message.includes("invalid.json: JSON.parse: end of data while reading object contents") ||    // Firefox
                message.includes("invalid.json: JSON Parse error: Expected '}'") ||                           // Safari
                message.includes("invalid.json: JSON.parse Error: Invalid character") ||                      // Edge
                message.includes("invalid.json: Syntax error")                                                // IE
              ),
              path: [],
              source: message => message.endsWith("test/specs/invalid/invalid.json"),
            }
          ]);
        }
      });
danielfcollier commented 1 year ago

From the Windows issue, I've seen that sometimes error messages might change after OS updates. @philsturgeon, what is the CI-CD workflow action that you are referring to?

Get a URL from https://github.com/APIDevTools/json-schema-ref-parser/actions

example: https://github.com/APIDevTools/json-schema-ref-parser/actions/runs/3411685713

philsturgeon commented 1 year ago

@danielfcollier here's an example of the ubuntu issue https://github.com/APIDevTools/json-schema-ref-parser/actions/runs/3553731434/jobs/5969417667