glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
11.79k stars 1.04k forks source link

Enhance testing capabilities #2509

Open Adam724 opened 5 months ago

Adam724 commented 5 months ago

Currently, there is no way to pass cliOptions in the automated tests, making it difficult to test these flags. This PR aims to solve that with the following:

  1. Adds a test configuration object in test/lib/optionMap.ts. This allows you to specify a test file path as key, and a configuration object as the value to customize the cliOptions, comparisonArgs, and target language for that test.
  2. If the current test language does not match that specified in optionMap, the test is skipped. This is necessary since different languages support different CLI options.
  3. Allows you to specify an input and expected output JSON file for tests. This is necessary since some cliOptions (such as omit-empty) are expected to produce a different JSON as output in some cases. I've adopted a standard file naming for input files matching this regex: /^(.*)\.in\.(.*)$/, and output files matching this regex: /^\1\.out\.\2$/. For example myCustomTest.in.json and myCustomTest.out.json. If an input file is found with no matching output, an error is thrown with a message indicating the issue.

No changes are necessary for any existing tests, this just adds the ability to write more customizable additional tests. Unsure if there is a better way to do this, any feedback is welcome!