Repository navigation
Conversation
|
When I run |
|
Yep, it also happens on master (a97029c). Here is what I see: https://gist.github.com/bolinfest/d76cf662b800f26a1c6d. |
0a59fa0 to
42059df
Compare
f98f32b to
b6089fb
Compare
This introduces support for a `--test-runner-bootstrap` flag to the Atom CLI
that can be used to specify the file passed to `runSpecSuite()` in
`spec-bootstrap.coffee`. Without threading this parameter through to `apm`,
this can be used directly with `atom` as follows:
```
atom --dev --test --test-runner-bootstrap /path/to/test-runner/bootstrap.js --spec-directory $PWD/spec
```
Note that, in this example, `/path/to/test-runner/bootstrap.js` must return a function that
takes no arguments and returns a new object that satisfies the `JasmineEnv` type defined in `jasmine-helper.js`.
The key methods that it needs to support are:
```
addReporter(reporter: JasmineRunner)
execute()
```
Here is a complete example of a possible implementation for `/path/to/test-runner/bootstrap.js`:
```js
'use babel';
class Env {
_reporters: JasmineRunner[];
_includedTags: string[];
constructor() {
this._testDirectory = atom.getLoadSettings().specDirectory;
this._reporters = [];
this._includedTags = [];
this._runner = new TestRunner(this);
}
addReporter(reporter: JasmineRunner) {
this._reporters.push(reporter);
}
execute() {
this._runner.execute();
}
setIncludedTags(tags: string[]): string[] {
// I doubt anyone relies on the return value, but this is how this method is implemented in
// https://github.com/atom/jasmine-tagged/blob/master/src/jasmine-tagged.coffee. I think this is
// an accident due to CoffeeScript.
return (this._includedTags = tags);
}
_reportRunnerStarting() {
for (let reporter of this._reporters) {
reporter.reportRunnerStarting(this._runner);
}
}
_reportRunnerResults() {
for (let reporter of this._reporters) {
reporter.reportRunnerResults(this._runner);
}
}
}
class TestRunner {
_env: Env;
_testDirectory: string;
constructor(env: Env) {
this._env = env;
this._testDirectory = atom.getLoadSettings().specDirectory;
}
execute() {
this._env._reportRunnerStarting();
console.log(`TODO: Run tests in ${this._testDirectory} and report results as they occur.`);
this._env._reportRunnerResults();
}
results(): JasmineNestedResults {
return {
passed(): boolean {
return true;
},
};
}
specs(): JasmineSpec[] {
return [];
}
topLevelSuites(): JasmineSuite[] {
return [];
}
}
module.exports = function() {
return new Env();
}
```
b6089fb to
9d788c4
Compare
There was a problem hiding this comment.
I was so close to getting all of them...
|
Thanks for taking this on. I'm pretty excited about starting to introduce static typing and also a path towards a more sane testing environment that breaks with legacy baggage. |
There was a problem hiding this comment.
📝 Would be great to doc testRunnerBootstrap in the comment for this method.
|
@bolinfest this looks like a great start to exploring types. Should we be installing any Atom packages to make use of the type information, linters, autocomplete, etc.? Do you have any screenshots/gifs of your setup where these types are used in Atom? Would be great to see what migrating will enable. Also, since this PR adds a new command line flag ( |
|
Don't suppose you want to bump up to Jasmine 2.x while you're at it? 😁 |
|
@joefitzgerald I'm working on building a car rather than a faster horse :P |
There was a problem hiding this comment.
@bolinfest Do you know if there's any documentation-generator tool that uses flow's type annotations to linkify things in the way that Atom's docs system does? If not, we should probably continue to use Atom's regular markdown-style doc format here, rather than these @param blocks.
There was a problem hiding this comment.
@maxbrunsfeld I don't know of one yet. But between flow ast [--tokens] and flow get-def, we can probably create a solid annotator for the source code. It looks like the comments aren't included in there.
If you wan't to stick with Atom's existing doc system, I'm not sure how you want this to interop. For example, how would you want to rewrite the following in JSDoc:
###
Section: Accessing the git repository
###Similarly, it looks like your Markdown usually uses asterisks for bullets that list parameters, but that would double the asterisk in my existing comment.
No matter what, I believe that you're going to need to do something different to extract the comments. Babel might be better than Flow for getting those nodes out of the AST.
|
@kevinsawicki If you don't want to install all of Nuclide (though you probably should, at least once, to fully understand our reported issues like facebookarchive/nuclide#203, which is why #8217 is so important to us), then I would recommend installing the following packages:
(Also, looking through the landing pages for those packages, is there a good way to store the images for the |
Not sure how this has anything to do with updating an outdated dependency (Jasmine) for which this PR directly addresses? Seems like an orthogonal statement. In any case, I'm interpreting your statement as "no". |
…ve test runner. In practice, the TerminalReporter seems to have all sorts of funny requirements due to a transitive dependency on `failure-tree.coffee`, which is something that only exists in @kevinsawicki's personal fork of `jasmine-node`: https://github.com/kevinsawicki/jasmine-node.git. To simplify things, this keeps all of the Jasmine-specific stuff in its own file. This simplifies the contract of a `--test-runner-bootstrap` such that its only requirement is to produce an object with an `execute()` method. It would be nice if the `execute()` method could return a `Promise` and have that handled properly, though that's a little messy because the `spec-bootstrap.coffee` file is currently written in CoffeeScript (so no async/await), which is in turn called from `atom-application.coffee`.
|
Okay, upon reviewing this, we have a plan that differs a bit from what you've come up with here. The good news is that I'm going to start implementing this myself today, with an aim to land it some time next week. Here are the details we have in mind, which I'm happy to discuss and adjust:
This should give your runner a blank-slate global environment, while at the same time giving it access to the raw materials needed to setup an environment that mimics Atom. You can instantiate an Atom environment and assign it to We tried running flow, but couldn't get the changed file to type check. Not sure if that's what you were explaining in your description, but I'm not really keen to add type signatures unless we can get |
|
@nathansobo Thanks for the detailed response! In general, this sounds good. I have only a couple of concerns. Let's say I'm creating my new test harness in a new package named "atomSpecRunner": "./node_modules/nuclide-test-harness/lib/atom-spec-runner.js",
"devDependencies": {
"nuclide-test-harness": "0.0.0"
}which is OK, but a bit verbose, and of course a little dicey because theoretically, Also, we would really like to get away from The How you use Flow is up to you. No, it won't work today because when you say Though as I said, there are many cases where you can at least get some signal from intra-file contracts, so maybe if you stick to those, you can still get Flow to work without reporting any errors. Note that you can also suppress Flow errors on an individual basis by specifying the format of the line comment to use for suppression in your https://github.com/facebook/nuclide/blob/master/pkg/nuclide/commons/.flowconfig#L12 If Flow fixes the error that you are suppressing in a future version, then using the annotation when there is nothing to suppress becomes a Flow error. It's pretty sweet. |
|
Also, I anticipate being in a transient state where some of our tests are written the old way and some are written the new way. By making it a command line option, I was planning to remap "scripts": {
"test": "apm test && atom --dev --test --test-runner-bootstrap ..."
}Or something like that. Then once I finished migrating all of my tests, it would just be one or the other. |
Ideally I'd like to resolve that field as if you passed it to
What about passing the command line arguments through to the test runner as parameters or something so you can handle this however you want?
This one is tricky. I'd really like packages to be able to bundle their own runners without users having to specify command line args. For example, a pretty common practice for me is to launch specs interactively from within Atom... it would be nice if the correct runner were just dealt with automatically. What about a |
|
OK, so if it gets passed to Passing the command line arguments through to the test runner would be good. Maybe even too general? If you could assume that all of the args were paths and then Atom did the work of resolving them to absolute paths before passing them to the runner, then I think that would be sufficient. I think that might even work better for your common practice of launching specs interactively from within Atom. (You could even support right-clicking on a spec and asking Atom to run it!) I can live without supporting my transient state use case. Thinking about it more, it's probably not worth building a hook for since it isn't something I would expect to exist long-term. At some point in the future (definitely not required now), it would be nice to come up with a more specific object model for talking to things like |
Nice idea. I'll try to think about a more abstract, path-oriented interface for running specs.
I'd really like to ditch our current reporter and let people experiment with their own libraries. I'd be keen to eventually provide a recommended reporting mechanism. I'm starting surgery now. I'll try to keep your concerns in mind and we can iterate until this fits. |
|
@bolinfest I'm going to close this now that #8968 has been merged. We can address any remaining issues as separate PRs. |
On a high level, I would like to be able to use an alternative test runner for running tests in Atom. (Currently, Atom uses Jasmine 1.3 for its test runner.) Atom already does a lot of great work to set up the test environment and to enable the test runner to run in-process, on par with other JavaScript in Atom.
Previously,
spec-bootstrap.coffeeloadedjasmine-helper.coffee, which in turn loadedvendor/jasmine,jasmine-tagged, andspec-helper.coffeeviaspec-suite.coffee(which installs a bunch of properties on the globalsjasmineandwindow, loadingjasmine-jsonandvendor/jasmine-jquery, to boot!). The net effect ofspec-bootstrap.coffeewas to set up a bunch of helpers for Jasmine, register some Jasmine reporters, and runjasmine.Env.execute().With this change, the only requirement to be a "test runner" is to be a function that takes a hash of options and synchronously returns an object with an
execute()method. This is much simpler. It also makes it possible to introduce a test runner that is completely independent from Jasmine.The default implementation maintains the old behavior:
jasmine-helper.coffeehas becomejasmine-helper.js. Where it used to export arunSpecSuite()function that could load an arbitrary file (which was alwaysspec-suite.coffee, in practice) and then create a newjasmine.Envandexecute()it, nowjasmine-helper.jsexportsrunSpecSuite()with its defaults baked in and it returns thejasmine.Envwithout executing it. Now it is up tospec-bootstrap.coffeeto decide whether to loadjasmine-helper.coffeeor some other file and to invoke theexecute()method on the resulting object that it creates.Here is an example of an alternative/trivial implementation of a custom test runner that satisfies the contract:
This PR introduces a new flag for the Atom executable,
--test-runner-bootstrap, that makes it possible to specify the source of the alternative test runner. For example, if the above were defined at/path/to/test-runner/bootstrap.js, then it could be used as a test runner as follows:Part of the work of this PR was defining the types for the Jasmine object model to clarify the contracts in
jasmine-helper.js. As Atom's test runner is an amalgam of Jasmine packages (jasmine,jasmine-json,jasmine-node,jasmine-tagged, andjasmine-focused), this was no easy task. These definitions appear at the top ofjasmine-helper.js(formerlyjasmine-helper.coffee). Writing this file in JavaScript makes it possible to do this using Flow types.Originally, I tried to implement this PR by making a "test runner" an object that satisfied the contract of
jasmine.Env. In practice, this turned out to be too difficult because so many libraries were adding expando properties ontojasminethat it made it too hard to get a full picture of the API that was required of Jasmine. For example, I was getting failures becausefailure-tree.coffeewas looking for (as far as I could tell) undocumented properties onjasmine.Specobjects. Note thatfailure-tree.coffeecomes from @kevinsawicki's fork ofjasmine-node(https://github.com/kevinsawicki/jasmine-node.git), making it tough to trace through. As such, trying to create ajasmine.Reporterthat met the needs of Atom's built-inTerminalReporterandAtomReporterobjects seemed too difficult. Admittedly, this means that a custom test runner will not be able to take advantage of the default UI that is provided for Atom tests, but for now, I think this is OK.Note that in
jasmine-helper.js, I did not hoist inlinerequire()calls asimportstatements because at least one of them has important side-effects, so it was unclear as to what was safe to move. I did my best to match Atom's JavaScript style, so I did not use semicolons, put spaces betweenfunctionand(), etc.Although
jasmine-helper.jsdoes not come close to Flow checking cleanly (Flow can't understand theCoffeeScript files when tracing through a
require()statement), I added an initial.flowconfigfile anyway so that basic features like click-to-symbol work in Nuclide. This also makes it possible
for Flow to report intelligent things about intra-file contracts.