-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
declare var test on global scope issue #1537
Comments
@jvanoostveen Can you just filter out mocha tests from TestCafe source files? |
The error is raised during bundling, TypeScript will load all the definitions it can find (or so it seems). |
Did I get it right: you are bundling production code and during compilation of the production code you get complains from TS compiler about mocha and TestCafe tests? |
Yes, except, I get the compiler error not on the tests, but on the definition files. |
Do you require/import TestCafe or mocha in your production files? |
Hey Guys, I'm encountering the same issue while using mocha and testcafe in the same project. I'm evaluating testcafe for end to end testing and have |
I haven't found a way around this, and as we're also evaluating, I've for now downgraded to |
The problem is that both mocha and testcafe are polluting the global scope (I'm guessing this is for good reasons). In such first glance, I would dump mocha and live with testcafe, while bringing a mocha replacement. Then again, I have no idea what are your project concerns and why you use mocha. |
polluting the global scope, looks like we're back in the early days of javascript... |
Use both of Mocha & TestCafe, would like to have some viable workaround. |
I guess you can use two tsconfig.json files: one for E2E tests and the second one for mocha tests. tsconfig.testcafe.json
tsconfig.mocha.json Each config will filter the appropriate files. |
Can someone share their setup? I still don't understand how both mocha and testcafe tests are mixed up and why they simultaneously compiled by TS and what production code bundling has to do with it all. |
The typescript compiler loads all types from |
When I change the static _getTypescriptOptions () {
// NOTE: lazy load the compiler
var ts = require('typescript');
return {
allowJs: true,
pretty: true,
inlineSourceMap: true,
noEmit: true,
noImplicitAny: false,
module: ts.ModuleKind.CommonJS,
target: 'ES6',
lib: ['lib.es6.d.ts'],
+ types: ['node', 'testcafe'],
baseUrl: __dirname,
paths: { testcafe: ['../../../../ts-defs/index.d.ts'] }
};
} But those types might not be enough for all cases, so loading and parsing of the I also noticed a new TypeScript program is created for each file, this might not be the fastest way... |
We are investigating it in context of the #1591 |
having the same issue with jest and #testcafe -> both expose |
Hi everyone! Let's determine the problem and try to solve it. As I understand you have a problem when you build your project, when TypeScript compiles the sources. Take a look at my tsconfig.json.
So, is something configured in the other way in your projects? Maybe I missed something? Feel free to create a Pull Request in my example repo to show your case. /cc @jvanoostveen, @qballer, @vasyas, @peterwestendorp, @Hotell, @oukayuka, everyone |
I still have to check our situation, I am unable to access the source code (🏖), maybe @peterwestendorp can check, but when – in your example – I add the {
"include": [
"unit/**/*.ts",
"e2e/**/*.ts"
]
}
So it is hard to compare, because it might also be the case that the definition file is not found anyway, if so changing When the Anyway, it doesn't seem that these issues are related to the original issue, where the compilation in TestCafe was causing the mocha definition conflict... So, back to the original case, running the TypeScript tests with TestCafe, when I add this to the
So it is not about compiling the rest of the code, but running the TestCafe files written in TypeScript. Did you manage to have those working with the example? |
heyo folks! check this:
thanks for starting to resolve this @AlexanderMoskovkin , your solution is kinda sub-optimal. Providing Even if we did that, there is still issue with testcafe handling of TSC, which I described in my PR PS: also I've created "issue" here microsoft/TypeScript#17663 |
I'd really like to use both jest and testcafe and typescript, and the currently problem regarding duplicate types (aka I think it would be helpful if testcafe could use a local test directory tsconfig.json that would allow specifying types. |
there is absolutely none :) you can see my PR's and description. Also folks from TS confirmed that my solution is "the only possible/best one" --> https://twitter.com/martin_hotell/status/894627899688574977 Although as I've mentioned in my comments zilion times, those solutions won't work for testcafe because it doesn't consume users tsconfig, but that's not a showstopper, you can use my solution and define npm script like this : what is |
quick fix is straightforward in testcafe's codebase just adding |
@Hotell Ah, ok, I'll try your |
Guys, thanks a lot for your investigations and clarifications, now the problem is clear for me. For now I suppose we can use the following solutions to resolve the problems:
Meanwhile we will think about more fundamental solutions (like taking into account |
@Hotell FYI, pre-compiling with tsc and my custom tsconfig.json worked a dream. Thanks again. // testcafe/tsconfig.json {
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist/testcafe",
"module": "es2015",
"target": "es2017",
"baseUrl": "",
"types": [
"testcafe",
"node"
]
}
} |
@mike-packetwerk cheers mate! |
I ran into the same issue and solved it by monkey-patching the tsconfig for testcafe: const TypeScriptTestFileCompiler = require('testcafe/lib/compiler/test-file/formats/typescript');
const _getTypescriptOptions = TypeScriptTestFileCompiler._getTypescriptOptions;
TypeScriptTestFileCompiler._getTypescriptOptions = () => {
const config = _getTypescriptOptions();
config.skipLibCheck = true;
return config;
} I hope this helps someone till this is fixed. |
@draconisNoctis thanks for the info. The fix is on the way. We're going to release a minor version with it at the start of the next week. |
See issue and comment : DevExpress/testcafe#1537 (comment)
I have latest 0.20.1 and still getting a subsequent variable declaration error as well as :
|
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow. |
Great to see TypeScript definition files with the package.
Unfortunately, we're having issues in a project that also uses Mocha. Both libraries have a
test
declaration on global scope, so TypeScript is throwing the following error:In
testcafe
package:declare var test: TestFn;
In
@types/mocha
declare var test: Mocha.ITestDefinition;
It's global scope all over again.
I would prefer to import
test
from the Testcafe package. Or is there some other solution to this?The text was updated successfully, but these errors were encountered: