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.

Cannot use global plugins with Typescript

See original GitHub issue

What are you trying to achieve?

I am trying to use plugins like tryTo globally in Typescript, however, it seems that they are not defined.

What do you get instead?

Typescript is throwing Cannot find name 'tryTo'.ts(2304)

Scenario('login', ({ I }) => {
  tryTo(() => I.amOnPage('/login'); // this fails
  I.seeElement({ name: 'login' });
  // ...
});

A workaround would be

const tryTo = codeceptjs.container.plugins('tryTo');

Scenario('login', ({ I }) => {
  tryTo(() => I.amOnPage('/login'); // this works, but parameters are any
  I.seeElement({ name: 'login' });
  // ...
});

However, tryTo then has no type definition (defined as any). My question would be if it is possible to use plugins like tryTo globally and with a type definition in Typescript (latter one being more important).

See this Stackblitz as example (note that there are a few more type issues).

Details

  • CodeceptJS version: 3.2.1
  • NodeJS Version: 14.17.6
  • Operating System: MacOS
Configuration file
require('ts-node/register');

exports.config = {
  tests: './src/e2e/tests/*_test.ts',
  output: './logs/e2e/',
  helpers: {
    Playwright: {
      url: 'https://localhost:8080/',
      show: !process.env.HEADLESS,
      browser: 'chromium',
    },
  },
  include: {
    I: './steps_file.js',
  },
  bootstrap: null,
  mocha: {},
  name: 'TS-Test',
  plugins: {
    pauseOnFail: {},
    retryFailedStep: {
      enabled: true,
    },
    tryTo: {
      enabled: true,
    },
    screenshotOnFail: {
      enabled: true,
    },
  },
};

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
PeterNgTrcommented, Oct 18, 2022
1reaction
jonguenthercommented, Jan 10, 2022

Thanks for your reply @emanuelwong , but as you mentioned in your quote, registerGlobal should be enabled by default if tryTo is set to enabled, so Typescript theoretically should pick it up, shouldn’t it? 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt Vue Typescript global plugins unavailable inside script ...
The only workaround is to create a function that uses them inside the mixin.ts files and extend them that way. Or import all...
Read more >
Plugins - Vue.js
Use global properties scarcely, since it can quickly become confusing if too many global properties injected by different plugins are used throughout an...
Read more >
Plugins directory - Nuxt
The plugins directory contains your Javascript plugins that you want to run before instantiating the root Vue.js Application.
Read more >
Plugins | Chart.js
inline plugins are not registered. Some plugins require registering, i.e. can't be used inline. const chart = new Chart(ctx, { plugins: ...
Read more >
How to create a global custom plugin in Nuxt.js
A global custom plugin can come in handy in a couple of situations. For example, let's imagine that you can't find an open...
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