Comments (15)
Would not dream of saying such a thing. Who uses Bower anyway these days? ;-) Just update #72 to pass the linting and this should be fixed.
from fake-timers.
Ah okay, I thought maybe not many folks at sinonjs were using Webpack, since sinon (before 2.0.0-pre) isn't Webpack-compatible. Working on fixing the jslint error...
from fake-timers.
from fake-timers.
I messed up when rebasing and merging in your changes, as I didn't run the linting (which failed due to migrating to ESLint where we disallowed Function
calls), and I had to revert the commit.
While just disabling that eslint
rule would be fine, I went on to inspect this further, seeing if the Function
call was necessary or not (or if we could just use your other solution), and I devised a test script to see if thing still worked:
var lolex = require("./src/lolex-src.js");
var clock = lolex.install();
fn = function() { console.log('should show immediately'); }
setTimeout(fn, 15000); // Schedules with clock.setTimeout
clock.tick(20000);
I compiled this using webpack --output.file out.js foo.js
and also created a index.html
with these contents:
<script src="./out.js" ></script>
What struck me was that this works without your patch in both the browser and in Node, so I am not sure which problem you are fixing? Could you please come up with the details necessary to recreate a failing testcase in the master
branch?
from fake-timers.
Sure, I wonder if it depends on the webpack config? I just checked and if I go into my chrome console and evaluate global
I get a ReferenceError
. So maybe webpack is polyfilling it? Or babel?
from fake-timers.
Yes, here it is: https://webpack.github.io/docs/configuration.html#node
Now to find out why that wasn't taking effect for me...
from fake-timers.
In any case wouldn't you want lolex-src.js
to work standalone in the browser, without being built into a webpack bundle?
from fake-timers.
we could probably go with typeof global === 'undefined' ? this : global
instead...
from fake-timers.
Okay, I think what happened was I was using sinon
< 2.0.0 in the browser (with Karma), and since sinon
< 2.0.0 is not webpackable, I was loading it and lolex
as webpack externals, hence no polyfill for global
was getting injected into lolex
. Make sense?
from fake-timers.
In addition I think usage of mochify
in your tests is also polyfilling global
in the code that gets run in phantomjs
.
from fake-timers.
Okay, repro is simple: just paste lolex-src.js
into a Chrome console and hit enter. You'll get Uncaught ReferenceError: global is not defined(…)
from fake-timers.
sigh the JS world can be so confusing these days. Yes, I was trying to use lolex as a webpack external so that I could use sinon 1.7 as a webpack external. I hadn't noticed that you basically require lolex to be built with browserify or webpack to use in the browser. In any case the global || this
at the bottom of lolex-src.js
is probably pointless
from fake-timers.
It already does. It's in the top level directory, lolex.js, built by
Browserify on each release.
- jul. 2016 16.25 skrev "Andy Edwards" [email protected]:
In any case wouldn't you want lolex-src.js to work standalone in the
browser, without being built into a webpack bundle?—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#71 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAluXJNdmWLM00PPNUgOwZXYgNdFTRAFks5qV5hsgaJpZM4I93P2
.
from fake-timers.
Well I'm closing this as invalid. Sorry for the trouble
from fake-timers.
No worries. This does show we need to update the docs, though. I see it says you need to build it yourself, which is incorrect.
from fake-timers.
Related Issues (20)
- Test failing since Node 18.8.0 HOT 2
- The `shouldAdvanceTime` option seems to cause Jest Test environment to clear during the test HOT 4
- `runToLastAsync` doing infinite loop when `now` is specified to setup clock
- [Feature] Jump forward in time to simulate throttled timers HOT 22
- requestAnimationFrame is passed incorrect argument HOT 8
- [Feature]: Speed up all fake timers HOT 12
- [Feature]: In Node, hijack perf_hooks.performance in addition to global.performance HOT 5
- TypeError Since Node 19 HOT 4
- NodeJS "timers" module is not mocked HOT 17
- Calls to `tick()` do not cause all setTimeouts to fire in specific scenarios. HOT 6
- Mock "timers/promise" module HOT 2
- NodeJS `timers` module mock causing tests to timeout in JSDom HOT 3
- process.hrtime gives incorrect results HOT 4
- Leave global scope untouched HOT 5
- How should `shouldAdvanceTime` work together with `Date`? HOT 1
- runAllAsync and runToLastAsync do not run code in the microtask queue HOT 5
- Cleanly switch to real time and back again to fake time while testing HOT 2
- Skypack bundle cannot be loaded in the browser HOT 5
- `install({ toFake: ["setImmediate"] })` fails when `setImmediate` is not available in context (such as browser environment) HOT 5
- Support performance.measure method
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fake-timers.