question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mocha Setup is not working in typescript based tests.

See original GitHub issue

Description

I have setup mocha as defined in the setupMocha example. But when I run in replay mode, the recordings are created again thus having duplicate recordings. Please note that I am using ts-mocha to run the tests like this, and the below code is in one of the tests I have.

Shareable Source

this is how we run the tests. "test:integ": "ts-mocha -p ./tests/integ/tsconfig.json --opts ./tests/integ/mocha.opts", mocha.opts

--timeout=60000
--reporter mocha-multi-reporters
--reporter-options configFile=./tests/integ/report-config.json
./tests/integ/config/test-setup.ts
./tests/integ/**/*.ts


const NodeHttpAdapter = require('@pollyjs/adapter-node-http');

const { Polly, setupMocha: setupPolly } = require('@pollyjs/core');
const FSPersister = require('@pollyjs/persister-fs');
const path = require('path');
Polly.register(NodeHttpAdapter);
Polly.register(FSPersister);
setupPolly({
    /* default configuration options */
    recordIfMissing: true,
    mode: 'replay',
    persister: 'fs',
    adapters: ['node-http'],
    persisterOptions: {
      fs: {
        recordingsDir: path.resolve(__dirname, '../recordings')
      }
    }
  });

Error Message & Stack Trace

There is no error but if I stop my app and run my functional tests then the tests should use the already recorded recordings since I set the mode as replay and also it should not record again and populate the recordings more.

Dependencies

Copy the @pollyjs dependencies from package.json:

    "@pollyjs/adapter": "^4.2.1",
    "@pollyjs/adapter-fetch": "^4.2.1",
    "@pollyjs/adapter-node-http": "^4.2.1",
    "@pollyjs/adapter-xhr": "^4.2.1",
    "@pollyjs/core": "^4.2.1",
    "@pollyjs/persister-fs": "^4.2.1",
    "@pollyjs/persister-rest": "^4.2.1",

Environment

Node.js v10.15.0 darwin 17.7.0 npm – 6.11.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:33

github_iconTop GitHub Comments

1reaction
raghanagcommented, May 23, 2020

Sorry @jasonmit , I have fixed my example and the back-end call is now getting recorded. It looks like we have to strictly follow the documentation. https://github.com/raghanag/polly-test/blob/master/recordings/Puppeteer-Suite_952821357/should-be-able-to-navigate-to-all-routes_1130491217/recording.har#L54

1reaction
raghanagcommented, May 17, 2020

I updated my app with replay mode and tested against the https://github.com/esausilva/example-create-react-app-express it has both front-end and back-end services, once I record the test, and replay the test when the back-end is down, it is working. Looks like PollyJS only records fetch, XHR. maybe my app is not using one of the methods. Thanks a lot @jasonmit

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocha test failing using typescript - Stack Overflow
My code builds and run fine but when I run the tests via npm run test they fail with a SyntaxError: Unexpected token...
Read more >
Mocha for TypeScript Testing: How to Get Started - Testim Blog
Install Development Dependencies for Mocha. First, make sure that you have Mocha installed. You can do this by running the following command ...
Read more >
Write tests for TypeScript projects with mocha and chai
In this post, I explain how to set up a simple setup where we can have our tests also written in TypeScript, wherein...
Read more >
Mocha/Chai with TypeScript - DEV Community ‍ ‍
I started searching and I found some informations about Mocha and Chai for writing tests in Javascript and in TypeScript but I had...
Read more >
Mocha | WebStorm Documentation - JetBrains
You can run Mocha tests from outside WebStorm, examine test results ... Make sure the JavaScript and TypeScript and Node.js required plugins ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found