percy / percy-testcafe

TestCafe client library for visual regression testing with Percy
https://docs.percy.io/docs/testcafe
MIT License
8 stars 4 forks source link

Error: Cannot prepare tests due to an error. #30

Closed DanielHabenicht closed 3 years ago

DanielHabenicht commented 3 years ago

I am getting the following error while doing mostly the same as in the tutorial/example. Am I still doing something wrong?

  1. Starting http-server
  2. Running tests (see command in output (3.):
    
    import { Selector } from "testcafe";
    import { Config } from "./testcafe.config";
    import percySnapshot from "@percy/testcafe";

fixture(Intro screens test).page${Config.baseUrl}; // base Url is http://localhost:8080

test("Finish intro screens", async (t) => { const nextButton = Selector("a").withAttribute("role", "button").child().withText("Weiter"); const websiteText = Selector("html").textContent;

const titleForIntro1 = "Willkommen bei der CovMap";

await t.expect(websiteText).contains(titleForIntro1); await percySnapshot(t, "Final Site"); });

3. Percy Fails
```bash
PS C:\Develop\GitHub\CovOpen\CovMapper> npm run percy

> covmap@0.1.0 percy C:\Develop\GitHub\CovOpen\CovMapper
> percy exec -- testcafe chrome testcafe/*.spec.js

[percy] Percy has started!
[percy] Created build #18: <redacted>/7450300
[percy] Running "testcafe chrome testcafe/*.spec.js"
 Running tests in:
 - Chrome 86.0.4240.75 / Windows 10

 Intro screens test
[percy] Could not take DOM snapshot "[object Object]"
[percy] Error: Cannot prepare tests due to an error.

Cannot implicitly resolve the test run in the context of which the test controller action should be executed. Use test function's 't' argument instead.
 √ Finish intro screens

 1 passed (4s)
[percy] Stopping percy...
[percy] Finalized build #18: <redacted>/7450300
[percy] Done!

If you more context is needed, this is the branch I am working on: https://github.com/CovOpen/CovMapper/tree/chore/percy-integration/testcafe

Robdel12 commented 3 years ago

Hey @DanielHabenicht! Thanks for the issue -- it looks like you're using the latest beta version of this SDK. The docs for how to use the latest (beta) version can be found here: https://github.com/percy/percy-testcafe#usage There are a lot of big changes made to the SDK. One being the first argument to percySnapshot is now the name (and no longer the test instance).

You'll want to update your test to remove that first arg:

test("Finish intro screens", async (t) => {
  const nextButton = Selector("a").withAttribute("role", "button").child().withText("Weiter");
  const websiteText = Selector("html").textContent;

  const titleForIntro1 = "Willkommen bei der CovMap";

  await t.expect(websiteText).contains(titleForIntro1);
  await percySnapshot("Final Site");
});

The docs on docs.percy.io haven't been updated yet, you'll want to refer to the README for setup & config.

DanielHabenicht commented 3 years ago

Thanks for the lighting fast feedback. Good to know that I should just read the master :)

Unfortunately your solution is bringing me back to #4 but this time if changed to import * as percySnapshot from ... Typescript errors:

This expression is not callable.
  Type 'typeof import("c:/Develop/GitHub/CovOpen/CovMapper/node_modules/@percy/testcafe/types/index")' has no call signatures.

There would be the option of calling percySnapshot.default but this also errors in TypeError: percySnapshot.default is not a function.

If run as js file the same Error as in my first comment surfaces.

wwilsman commented 3 years ago

So it looks like we inadvertently released the beta on the latest channel which is why you accidentally found yourself on the beta following the docs. I've since deprecated the first beta, released a new "previous" version to be tagged as latest, and now the new beta.2 lives on the @next channel.

Feel free to continue using the beta to help us vet out any bugs, but now you are able to install 0.2.1 and follow the guides on the site along with not having to install the new @percy/cli.

Back to the beta discussion, those types are found here and look to be valid as well as the type tests are passing without issue. Curious what might be going on to cause those type issues? 🤔

DanielHabenicht commented 3 years ago

I have looked into it a bit but I don't get it. image @percy/testcafe is imported fine, but Typescript transpiles it with a default function. This has something to do with https://www.typescriptlang.org/tsconfig#esModuleInterop and that my project is using "module": "esnext", and yours is using the default tsconfig, thus "module": "commonjs",. I have already sunken to much time into it and will try the 0.2.1

DanielHabenicht commented 3 years ago

Baaam, made it. So it seems that testcafe has its own tsconfig.json which leads to ignoring my tsconfig.json. Specifying my tsconfig.json in the testcaferc.json solved the problem:

{
  "tsConfigPath": "./tsconfig.e2e.json"
}

The key is to include esModuleInterop like so:

{
  "compilerOptions": {
    "esModuleInterop": true
  }
}

As this is an extension solely for testcafe specifying a tsconfig.json for this project which is compatible with the tsconfig.json of testcafe might also solve this problem.

DanielHabenicht commented 3 years ago

Back to the error from the beginning :( Switched to version 0.2.1 and everything is working almost fine. Do you have any idea why certain parts of the background do not show in Percy screenshots? We have a map in the background which does not show up...

Robdel12 commented 3 years ago

I think I answered the map question via support -- is that right? :D I want to double check. If not send over a build link and we can take a closer look

DanielHabenicht commented 3 years ago

yep, you did :) Thx again.

Any idea how to investigate the error?

github-actions[bot] commented 3 years ago

This issue is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 3 years ago

This issue was closed because it has been stalled for 28 days with no activity.