Skip to content
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

Consider migrating the Jasmine codebase to Typescript or ECMAScript 6 #1800

Closed
Maximaximum opened this issue Mar 13, 2020 · 5 comments
Closed

Comments

@Maximaximum
Copy link
Contributor

Currently all the Jasmine codebase is written in pure Javascript, and we cannot use the latest, convenient ECMAscript features (like template strings, const/var declarations etc) to develop/maintain the Jasmine core functionality.

In order to be able to use the es6 features, the build process has to include transpilation from es6 (or higher)-compliant syntax to the older es syntax supported by all the browsers supported by Jasmine (including IE10).

One of the tools that can be used for transpiling the code is Babel.

Another option, however, would be to use Typescript. IMHO, this would enhance the project even more, because Typescript enables writing code faster and catching certain bugs during compilation. Any Typescript projects that use Jasmine for testing, would benefit from that as well, because currently the typings for Jasmine are not that good IMO, since they are not natively supported by Jasmine itself.

@sgravrock
Copy link
Member

I personally like working with Typescript so I've thought about this from time to time. There are a couple of problems that have stopped me from proposing it, though. My biggest concern is that Jasmine's own build toolchain might introduce polyfills or otherwise modify the global environment in such a way as to cause tests that should have failed to pass. E.g. if a user who intends to support IE inadvertently writes code that depends on promises, the tests should fail on IE. It would be unfortunate if Jasmine caused the tests to pass by poyfilling promises.

See also my latest coment on #491.

So I can see a few approaches:

  1. Find the --no-really-dont-modify-the-global-environment-no-matter-what setting for whatever build tools are chosen. (I don't think it exists but I'm by no means a Babel/Webpack expert and I'd love to be proven wrong about this.)
  2. Decide that we're OK with Jasmine affecting the behavior of user code in older browsers.
  3. Stick with the current approach of writing in the dialect of Javascript that runs in all our supported environments.

@Maximaximum
Copy link
Contributor Author

Yeah, valid point. I guess that option 2 is not really acceptable. So, need to investigate option 1

@Maximaximum
Copy link
Contributor Author

It seems like Babel provides a way to polyfill features without modifying the global scope. However, it seem like some features can't be polyfilled this way: https://medium.com/@lee_85949/polyfilling-a-javascript-library-the-right-way-337806a54152

Anyway, I'm not a Babel/Webpack expert neither (unfortunately), so I won't be able to easily create a config for that.

@nicojs
Copy link
Contributor

nicojs commented Mar 16, 2021

You might already know this, but (AFAIK) TypeScript never polyfills globals. If you try to use promises, but your compile target is es5, it will result in a compile error. Any polyfills you might want to use should be loaded manually and enabled with the --lib compiler option. For example: --lib es2015.promises

Example playground link: https://www.typescriptlang.org/play?target=1&module=1#code/FAYw9gdgzgLgBABzgXjgBQE5gLYEsoCmAdBgVGADYBuBAFAJQDcQA

@sgravrock
Copy link
Member

It turns out that some problems can be solved by waiting until they go away. The upcoming 4.0 release (schedule: it will be ready when it's ready, but sometime 3-9 months from now is a reasonable guess) will drop support for IE and some older Safari versions. At that point we'll be able to use nearly all of ES2015 without transpiling.

As for TypeScript, I don't think it's in the cards. I've gained some more experience converting JS codebases to TypeScript since this issue was first opened. That experience has me convinced that a TypeScript conversion is likely to exceed our dev time and risk budget, even for a major release where nothing else changes. It would also considerably raise the bar for contributing to Jasmine. Jasmine pushes the limits of TypeScript pretty hard, particularly in the matcher system. That's historically been one of the areas most contributed by people outside the core team. I'd rather not lose out on those contributions just because someone doesn't have a high level of TypeScript skill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants