Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Conversation

@lrhacker
Copy link
Contributor

Summary

Fixes #91

This change describes the exports from index.js in index.d.ts, so that TypeScript can properly resolve import statements for the module. It also includes running the format command on the index.d.ts file.

Details

I was seeing the "File 'node_modules/@cypress/skip-test/index.d.ts' is not a module." error when trying to add

import { onlyOn } from '@cypress/skip-test';

to a test file in my project that was written using TypeScript. By modifying index.d.ts with the changes in this PR, I was able to resolve the error.

Test file in cypress/integration/sample_spec.ts:

import { onlyOn, skipOn, isOn } from '@cypress/skip-test'; // This import previous resulted in an error onlyOn('mac', () => { // this callback will only evaluate on Mac // thus the tests will be completely hidden from other platforms describe('Mac tests', () => { it('works', () => { Cypress.log({name: 'On Mac?', message: isOn('mac')}); Cypress.log({name: 'On Windows?', message: isOn('windows')}); }); }); }); onlyOn('windows', () => { // this callback will only evaluate on Windows // thus the tests will be completely hidden from other platforms describe('Windows tests', () => { it('works', () => { Cypress.log({name: 'On Mac?', message: isOn('mac')}); Cypress.log({name: 'On Windows?', message: isOn('windows')}); }); }); }); skipOn('mac', () => { // this test will run on every platform but Mac it('hides this test on Mac', () => {}); });

Test output:
image

My Cypress tsconfig.json:

{ "compilerOptions": { "target": "es5", "lib": ["es5", "dom"], "types": ["cypress"], }, "include": [ "**/*.ts" ] }

My project's root tsconfig.json:

{ "compilerOptions": { "target": "es2019", "lib": ["es2019", "dom"], "module": "commonjs", "skipLibCheck": true, }, "include": [ "**/*.ts" ], }
@CLAassistant
Copy link

CLAassistant commented Feb 24, 2021

CLA assistant check
All committers have signed the CLA.

@KiaFarhang
Copy link

Hi @lrhacker - thanks so much for opening this! Do you know if there are plans to merge it? We're running into the same TypeScript issues and would love for this PR to merge and solve them. CCing @bahmutov to get your thoughts as well.

Appreciate the time working on this!

@lrhacker
Copy link
Contributor Author

Thank you, @KiaFarhang! I have not heard one way or another about it being merged yet, but I am keeping an eye on it if there turn out to be any changes needed!

@MCFreddie777
Copy link
Contributor

Will this be merged anytime soon?

@bahmutov bahmutov merged commit 01a994b into cypress-io:master Jun 8, 2021
@bahmutov
Copy link
Contributor

bahmutov commented Jun 8, 2021

Super, thank you

@bahmutov
Copy link
Contributor

bahmutov commented Jun 8, 2021

🎉 This PR is included in version 2.6.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@F3n67u
Copy link

F3n67u commented Aug 5, 2021

How can I use cy.skipOn without import @cypress/skip-test

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

7 participants