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

Allow singling out a particular test #346

Open
nzakas opened this issue Oct 28, 2015 · 6 comments
Open

Allow singling out a particular test #346

nzakas opened this issue Oct 28, 2015 · 6 comments

Comments

@nzakas
Copy link
Contributor

nzakas commented Oct 28, 2015

One of the issues I've been having as I'm trying to fix things is that the custom test runner is a bit difficult to work with when trying to focus on a specific issue. After several cycles of commenting out every test except the one I'm working on, I hacked in testOnly, testFailOnly and testAssertOnly locally and found that it really helped. Basically, the first one of these wins and all other tests are ignored. Here's the diff:

diff --git a/test/driver.js b/test/driver.js
index ed48ace..a582b93 100644
--- a/test/driver.js
+++ b/test/driver.js
@@ -1,16 +1,32 @@
 (function(exports) {
-  var tests = [];
+  var tests = [], only = false;

   exports.test = function(code, ast, options) {
+    if (only) return;
     tests.push({code: code, ast: ast, options: options});
   };
   exports.testFail = function(code, message, options) {
+    if (only) return;
     tests.push({code: code, error: message, options: options});
   };
   exports.testAssert = function(code, assert, options) {
+    if (only) return;
     tests.push({code: code, assert: assert, options: options});
   };

+  exports.testOnly = function(code, ast, options) {
+    tests = [{code: code, ast: ast, options: options}];
+    only = true;
+  };
+  exports.testFailOnly = function(code, message, options) {
+    tests = [{code: code, error: message, options: options}];
+    only = true;
+  };
+  exports.testAssertOnly = function(code, assert, options) {
+    tests = [{code: code, assert: assert, options: options}];
+    only = true;
+  };
+
   exports.runTests = function(config, callback) {
     var parse = config.parse;

Would you be open to including this in Acorn?

@marijnh
Copy link
Member

marijnh commented Oct 28, 2015

If someone has good experiences with a test runner module, I'm also definitely open to moving to a proper test framework. (I haven't run into any I liked, but I haven't used a lot.)

@RReverser
Copy link
Member

@marijnh That would be great. Personally, I like Mocha, but we could also stick with something as minimal as Tape. However, we still need to use own wrappers for AST comparison in any case.

@platinumazure
Copy link

For what it's worth, typescript-eslint-parser has recently moved to Jest for testing. Jest has a snapshot feature which may or may not be useful to this project for AST deep-compares. Would that be worth looking into at all?

@RReverser
Copy link
Member

@platinumazure I played with snapshots (without Jest) for Acorn tests, but not quite sure yet if it helps - diffs are still way too noisy and now you need to check two places instead of one when updating them, so decided not to proceed for now.

@marijnh
Copy link
Member

marijnh commented Sep 13, 2017

I'm not a big fan of snapshot testing -- using unvetted possibly wrong output as reference data, and committing huge blobs of that to the repository, feels dirty, and as @RReverser mentions, working with them often gets noisy and awkward. But I'm willing to be convinced if someone has good arguments in favor of it.

@KentAKA1970
Copy link

Thanks
Thanks

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

No branches or pull requests

6 participants
@nzakas @marijnh @platinumazure @RReverser @KentAKA1970 and others