wimdeblauwe / testcontainers-cypress

Testcontainers module for running Cypress tests
Apache License 2.0
64 stars 18 forks source link

Full example #48

Closed xgp closed 2 years ago

xgp commented 2 years ago

Hi! I think this is a great idea, but I'm having trouble getting an example working. I'm trying to run your example JUnit 5 DynamicTests.

Here's how I've built the layout, following the README:

└── src
    └── test
        ├── e2e
        │   ├── cypress
        │   │   ├── fixtures
        │   │   │   └── example.json
        │   │   ├── integration
        │   │   │   └── spec.cy.js
        │   │   └── support
        │   │       ├── commands.js
        │   │       └── e2e.js
        │   ├── cypress.config.js
        │   ├── package-lock.json
        │   ├── package.json
        │   └── reporter-config.json
        ├── java
        │   └── io
        │       └── phasetwo
        │           └── cypress
        │               └── CypressIntegrationTest.java
        └── resources
            └── logback-test.xml

In the build portion of my pom.xml I have:

    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
      </testResource>
      <testResource>
        <directory>src/test/e2e</directory>
        <targetPath>e2e</targetPath>
      </testResource>
    </testResources>

However, the test phase starts and just hangs here:

[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) @ cypress-test ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running io.phasetwo.cypress.CypressEndToEndTests
20:26:17.032 [main] INFO  org.testcontainers.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
20:26:17.104 [main] INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
20:26:18.386 [main] INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
20:26:18.387 [main] INFO  org.testcontainers.DockerClientFactory - Docker host IP address is localhost
20:26:18.426 [main] INFO  org.testcontainers.DockerClientFactory - Connected to docker:
  Server Version: 20.10.17
  API Version: 1.41
  Operating System: Docker Desktop
  Total Memory: 3934 MB
20:26:18.585 [main] INFO  🐳 [testcontainers/ryuk:0.3.3] - Creating container for image: testcontainers/ryuk:0.3.3
20:26:18.821 [main] INFO  org.testcontainers.utility.RegistryAuthLocator - Credential helper/store (docker-credential-desktop) does not have credentials for https://index.docker.io/v1/
20:26:19.039 [main] INFO  🐳 [testcontainers/ryuk:0.3.3] - Container testcontainers/ryuk:0.3.3 is starting: a4aaa125130cc71841f6364be90a8e5ec3246927fcd6619e817121e33fe5212f
20:26:20.213 [main] INFO  🐳 [testcontainers/ryuk:0.3.3] - Container testcontainers/ryuk:0.3.3 started in PT1.759624S
20:26:20.237 [main] INFO  org.testcontainers.utility.RyukResourceReaper - Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
20:26:20.238 [main] INFO  org.testcontainers.DockerClientFactory - Checking the system...
20:26:20.240 [main] INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
20:26:20.244 [main] INFO  🐳 [testcontainers/sshd:1.1.0] - Creating container for image: testcontainers/sshd:1.1.0
20:26:20.392 [main] INFO  🐳 [testcontainers/sshd:1.1.0] - Container testcontainers/sshd:1.1.0 is starting: fa393a65eee6f72d360e8dd6900a92a2ffe27e783a384f6ba55fa16ecffee9ca
20:26:22.176 [main] INFO  🐳 [testcontainers/sshd:1.1.0] - Container testcontainers/sshd:1.1.0 started in PT1.932009S
20:26:22.867 [main] INFO  🐳 [cypress/included:10.7.0] - Creating container for image: cypress/included:10.7.0
20:26:24.476 [main] INFO  🐳 [cypress/included:10.7.0] - Container cypress/included:10.7.0 is starting: fcc6ee570d989c7a11a1936dd1567562c23b67acf2b25feed79eb8bbf6a9d309
20:26:26.535 [main] INFO  🐳 [cypress/included:10.7.0] - Container cypress/included:10.7.0 started in PT3.66776S

Any ideas what I'm missing? Thank you!

xgp commented 2 years ago

Did some logging in CypressEndToEndTests to determine it never runs the tests (or the container hangs on returning test results).

    try (CypressContainer container = new CypressContainer().withLocalServerPort(port)) {
      container.start();
      //gets here
      CypressTestResults testResults = container.getTestResults();
      //never gets here
      return convertToJUnitDynamicTests(testResults); // (2)
    }
wimdeblauwe commented 2 years ago

Did you wait long enough? The container.getTestResults() call hangs until all tests have run.

xgp commented 2 years ago

Yes. I let it run for a long time. And I only had a single no-op test that returns immediately. spec.cy.js:

describe('My First Test', () => {
  it('Does not do much!', () => {
    expect(true).to.equal(true)
  })
})
wimdeblauwe commented 2 years ago

And is your test running from cypress itself? Go to src/test/e2e directory and run npx cypress open to check.

xgp commented 2 years ago

my mistake. It was an incorrect specPattern in the cypress.config.js file. It assumes by default your tests will be in cypress/e2e/**/*.cy.{js,jsx,ts,tsx}, but the project structure had them in cypress/**/*.cy.{js,jsx,ts,tsx}