convert-svg icon indicating copy to clipboard operation
convert-svg copied to clipboard

Improve test framework

Open neocotic opened this issue 6 years ago • 0 comments

The current test setup includes a lot of repetition. While this does ensure that the code is thoroughly tested, it would be good to reduce some of this repetition in order to speed up the build process.

Initially, I think a lot could be said for adding more structure to the test descriptors. I'd especially like to separate tests for convert methods with tests for convertFile.

We also need to add tests for the CLI. I think these should also be kept separate from the API methods so that we can fine grain the tests to target the CLI. We need to cover all 3 flows for the CLI as well (i.e. files, STDIN -> STDOUT, STDIN -> filename), but we should be able to reuse the same tests. All options should be covered by these tests. The CWD should be set based on whether or not the test is "core" (i.e. defined in convert-svg-test-helper).

For example;

{
  "api": {
    "convert": {
      "failure": [
        {
          "name": "...",
          "file": "...",
          "options": {},
          "message": "..."
        }
      ],
      "success": [
        {
          "name": "...",
          "file": "...",
          "options": {},
          "message": "..."
        }
      ]
    },
    "convertFile": {
      "failure": [
        {
          "name": "...",
          "file": "...",
          "options": {},
          "message": "..."
        }
      ],
      "success": [
        {
          "name": "...",
          "file": "...",
          "options": {},
          "message": "..."
        }
      ]
    }
  },
  "cli": {
    "failure": [
      {
        "name": "...",
        "args": [],
        "file": "...",
        "stdin": false,
        "stdout": false,
        "message": ""
      }
    ],
    "success": [
      {
        "name": "...",
        "args": [],
        "file": "...",
        "stdin": false,
        "stdout": false,
        "message": ""
      }
    ]
  }
}

It might also be good to only run a specified number of success and/or failure tests against the methods on API, since this is much slower than those on Converter (as these tests share an Converter instance which avoids lots of Chromium instances being created and destroyed).

I realize that these changes might make the JSON a bit more noisy, but it should make it easier to manage. We could even consider splitting the above into multiple files, if it would help.

I'm not sure if it should fall under this issue, but I'd also like to replace our fixture images to some created by us. I'm not sure about the origin of these images, to be honest, as I took them from svg2png which was my inspiration for the original convert-svg-to-png package, released under WTFPL. Since these are technically published by convert-svg-test-helper, however, I'd feel more comfortable owning them. The standard.svg is an exception, which I grant permission to use, however, even then I would like to use completely impartial images that serve the unique purpose of testing these packages.

neocotic avatar Nov 03 '17 15:11 neocotic