Repository navigation
Enable custom package testing environments - #8968
Conversation
|
Just a note -- I added this to the list of tasks above:
I think that will help package authors understand and switch to the new workflow. It can definitely be done as a separate PR, but wanted to add it here so we don't forget. ✌️ |
Thanks @izuzak. I actually realized I forgot to list that as I was falling asleep last night. |
69df44f to
b04bd25
Compare
|
What will the value of An easy solution is probably to include the absolute path to the Atom package being tested. That way, if the test runner wants to have a default place where tests (or fixtures) live, it can find that by resolving the expected subpath against the location of the Atom package. So if the property were named import path from 'path';
// Note this assumes testPaths can be a mix of files and directories.
function runTests({pathToAtomPackageUnderTest, testPaths}) {
if (testPaths.length === 0) {
testPaths = [path.join(pathToAtomPackageUnderTest, 'spec')];
}
// Proceed...
}The nice thing about this is that running tests for the entire package is still as simple as invoking Also, what is the return value of the function exported by |
|
Thinking about this more, |
Currently
I'm not convinced a default path is worth the added complexity. The lines of code aren't that big of a deal, but it's just one more magical thing to remember about the command rather than the simple story that the command does what you tell it to do.
Hadn't thought about it yet, but a promise resolving to an error code makes sense. I'm going to provide access to |
b04bd25 to
d68c950
Compare
|
@nathansobo I'm not saying the user should have to supply a default path: I'm saying the test runner should be given the option to infer one. (Again, this makes it possible to eventually support a feature in Atom that lets you right click on an Atom package and run all of its tests. Without this, you would always have to prompt the user to ask where the tests are.) But even if you don't agree with that, I think it makes sense to pass the location of the Atom package, or at least its |
|
Also, as I'm currently dealing with tests that fail to terminate, it would be nice if |
f18692b to
4fada32
Compare
a995637 to
f2824e1
Compare
|
mocha would be great! IMHO, features like |
8ba015f to
0e6aa3f
Compare
c49f3ed to
0c5aa93
Compare
They’re just window initialization scripts, and this new naming makes that a lot clearer.
For some reason, logging to stderr/stdout from the render process only works when Atom is run via child_process.spawn, which is how `apm test` invokes it. I’m trying to make a convenient interface for running tests directly via the `atom` command, and this is the only way I could find to long to stdout from the render process. I’m also choosing stdout rather than stderr because in this case, you’re intentionally running the tests and want to see feedback.
If the nearest containing package.json of a test path has an atomTestRunner field, we’ll require the specified file as a test runner rather than the default jasmine runner.
|
OK, I put up a quick fix so that I can use |
|
Hmm, I see there is a |
|
OK, for reference, here is the new skeleton I am using for a custom test runner. Is this what is expected? 'use babel';
/* @flow */
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
type TestRunnerParams = {
/** Absolute paths to tests to run. Could be paths to files or directories. */
testPaths: Array<string>,
/** A boolean indicating whether or not the tests are running headless. */
headless: boolean,
/** Creates the `atom` global object. */
buildAtomEnvironment: (params: BuildAtomEnvironmentParams) => AtomGlobal,
/** Currently undocumnted, but seemingly necessary to use buildAtomEnvironment(). */
buildDefaultApplicationDelegate: () => Object,
/** An optional path to a log file to which test output should be logged. */
logFile: ?string,
/** Unclear what the contract of this is, but we will not be using it. */
legacyTestRunner: () => void,
}
type BuildAtomEnvironmentParams = {
applicationDelegate: Object,
window: Object,
document: Object,
configDirPath?: string,
enablePersistence?: boolean,
}
/**
* This function satisfies the contract for a custom Atom test runner.
*/
export default async function({
testPaths,
buildAtomEnvironment,
buildDefaultApplicationDelegate,
}: TestRunnerParams,
): Promise<number> {
let applicationDelegate = buildDefaultApplicationDelegate();
let params = {
applicationDelegate,
window,
document,
};
global.atom = buildAtomEnvironment(params);
// TODO: Run tests for testPaths.
// Exit with zero if successful.
return 0;
} |
|
Just so everyone knows, we figured this out: atom/grim@8807010#commitcomment-13887073 We also concluded that the |
Sorry, it turns out that the error we were seeing was due to an attempt to subclass the existing |
|
When running a test, is there any way to remove all of the output that surrounds what I write to |
|
Currently, it seems like specifying a |
|
@bolinfest see #10952. |
|
Hmm, so there's also no way to specify additional flags/arguments to your test runner? Maybe we could use I can specify flags via environment variables and read them out of |
|
We're working on making this more official and documented. |
|
Nah it's cool, I already wrote my own... =) Just realised too damn late the reason it wasn't running is because the |
|
It'd be lovely if we could use "atomTestRunner": {
"path": "./path/to/test-runner",
"config": {
…
}
}The |
|
@nathansobo, making it official and documented will be great, but it takes some time, meanwhile, may you please explain in a nutshell how we can take use of it today? It seems there is already a mocha plugin, and I can wait to launch some mocha test in Atom. Existing mocha integration are not good, it seems Nuclide starts something in that direction but too much bloated to even understand it. Thanks. |
|
@nathansobo Try this. Seriously. :) |
|
@Alhadis Looks pretty cool. I like the black background. I'll keep it in mind next time I'm considering a runner, but right now I'm pretty deep into fixing some international keybindings stuff. |
|
@yamsellem You can specify a path in your |



This PR aims to improve the experience of running tests in Atom in a few ways.
atomTestRunnerfield in theirpackage.jsoncontaining a require path. If the field is present, Atom will resolve the path relative to the package's root, expecting the required module to export a function which it will invoke with an object containing the following parameters.testPathsAn array of paths to tests to run. Could be paths to files or directories.buildAtomEnvironmentA function that can be called to construct an instance of theatomglobal (it won't automatically be assigned toglobal.atom, that is left to the test runner to decide.logFileAn optional path to a log file to which test output should be logged.headlessA boolean indicating whether or not the tests are running headless.legacyTestRunnerThis function can be invoked to run the legacy Jasmine runner, giving packages a chance to transition to a new test runner while maintaining a subset of their tests in the old environment.atomCLI has been streamlined. Simply runatom --test path1 path2to invoke the test runner on the listed paths, expanded relative to the working directory. The--spec-directoryoption will be deprecated.buildAtomEnvironmentfunction will construct a clean Atom environment whose state can be reset via a call toresetin between test runs.Refs #8917
/cc @bolinfest @maxbrunsfeld
Additional Thoughts
Atom's current testing environment has been around since the very first day of Atom development, and is quite a mess. We assign all kinds of globals and mock the clock in evil and inconsistent ways that can cause quite a few headaches when writing tests for new packages.
This PR will give us a good way to make a fresh start. Ideally, a default test runner isn't something we should be supporting in Atom core. Every package should specify its preferred runner, which it can pull in as a development dependency and which Atom can interact with via an evolving interface. It would be good to have a recommended test framework. As it stands I'd probably want to switch bundled packages over to Mocha/Chai, unless people have other suggestions. Someday in the distant future we can finally delete the tangled mess that is our current default testing environment, but we'll keep it around for now.
Tasks
atomTestRunnerfield containing a path.buildAtomEnvironmentto test runners and use it to assign theatomglobal in the default test runner, rather than in the test window initialization script.AtomtoAtomEnvironmentresetmethod to Atom environmentlegacyTestRunnerparameter.--spec-directoryCLI option--spec-directoryinapm test(Drop --spec-directory apm#445)specDirectoryparameter when running tests interactivelyRun All Testscommand from Atom since it's broken.process.stdout.writeandprocess.stderr.writein the test windowipcto methods onApplicationDelegatedefaultTargetof the keymaps in theAtomEnvironmentconstructor.configDirPathand don't attempt any disk I/O inConfigorAtomEnvironmentif it is undefined. This will allow us to remove several mocks from the spec helper that prevent reading and writing state.config.load()into theAtomEnvironmentconstructor, which will be a no-op in specs where the config dir is undefined. This will allow us to moveloadBaseStyleSheetsback into the constructor as well so they are available in the environment's default state.core.autoHideMenuBarintoAtomEnvironmentconstructor.applicationDelegate,window,document)