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

hope can support optional test #3592

Closed
1 of 4 tasks
bluelovers opened this issue Nov 29, 2018 · 12 comments
Closed
1 of 4 tasks

hope can support optional test #3592

bluelovers opened this issue Nov 29, 2018 · 12 comments
Labels
status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior

Comments

@bluelovers
Copy link

bluelovers commented Nov 29, 2018

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

hope can support optional test

when that optional test is fail, will only show notice, but not make current test suite count as fail

describe('main', function ()
{

	it('test1', function ()
	{
		// do something without fail
	})

	it.optional('test2', function ()
	{
		// do something maybe with fail, but will not make current main count as fail
	})

});

Expected behavior: [What you expect to happen]

  test\optional.test.ts
    main
      √ test1
      x test2 (optional)

  ... display test2 fail like normal fail message

  1 passing, 1 optional fail

but the optional.test.ts is still pass

Actual behavior: [What actually happens]

Reproduces how often: [What percentage of the time does it reproduce?]

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version:
  • The output of node --version:
  • The version and architecture of your operating system:
  • Your shell (bash, zsh, PowerShell, cmd, etc.):
  • Your browser and version (if running browser tests):
  • Any other third party Mocha related modules (with versions):
  • The code transpiler being used:

Additional Information

@Bamieh Bamieh added the type: feature enhancement proposal label Dec 3, 2018
@Bamieh
Copy link
Contributor

Bamieh commented Dec 3, 2018

Hello @bluelovers 👋 thanks for the suggestion,

My thoughts on this:
Wrapping the it in an if statement is better since it gives you the "optional" feature plus a condition on when this case is optional.

I am generally against having optional cases in the tests, I'd rather modify the assertion inside the case, or wrap the case in an if clause.

@dotnetprofessional
Copy link

Optional tests sounds weird, but I myself had had the occasion for them. In so far as I want to run some tests for certain environments. I've used tagging for this however and controlled that via the options. @Bamieh I wouldn't like to recommend any type of conditional logic in a test, as then one needs a test for the test :)

@bluelovers
Copy link
Author

any way make if one of current mocha test is fail, at end will not count mocha is fail

@plroebuck
Copy link
Contributor

Give example test for your problem, pls!

@bluelovers
Copy link
Author

hmm, my english enough for detail say what i mean


for example

i wanna run a mocha test when npm publish

and i wanna if some of mocha test is fail , will not break script task

a little like env chk https://node.green/

image

just wanna do some chk for see it is support or not in current env (by mocha)

  "scripts": {
    "docs": "npx typedoc --options ./typedoc.config.js",
    "local-delete-cache-db": "ts-node ./test/lib/delete-cache.ts",
    "prepack": "echo prepack",
    "postpack": "echo postpack",
    "publish": "echo publish",
    "postpublish": "echo postpublish && node ./script/publish-after",
    "prepublishOnly": "npx npm-check-updates -u --packageFile ./package.json && npm run test",
    "test": "npm run test-ts",
    "test-js": "npx mocha \"!(node_modules)/**/*.+(test|spec).js\"",
    "test-ts": "npx mocha --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
    "travis": "typedoc --options ./typedoc.config.js"
  },

@plroebuck
Copy link
Contributor

None of what you've provided shows a test you are concerned about. Mocha will fail the run if any of your tests fail. If you need to conditionally skip a test at runtime (e.g., due to environment), do your check in before and then this.skip if test cannot be run; the test will be marked as pending and run will complete successfully.

@boneskull
Copy link
Contributor

Thanks for the suggestion. If you need to avoid a particular test in a particular environment, detect the environment, then conditionally call this.skip() in a test or hook.

@boneskull boneskull added status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior and removed type: feature enhancement proposal labels Apr 11, 2019
@boneskull
Copy link
Contributor

duplicate of probably other issues as well

@bluelovers
Copy link
Author

bluelovers commented Apr 12, 2019

i don't wanna skip it, i wanna test it, but skip error for complete successfully, and will display error message

@plroebuck
Copy link
Contributor

Programmatically, you could probably change the done callback to set process.exitCode = 0. Failures would not have the "optional" labeling, but complete successfully it does.

@bluelovers
Copy link
Author

i try add

https://github.com/bluelovers/node-segment/blob/a4019ffe3e53abbbf4775cf253aabe468812be5f/test/fixme.test.ts#L42-L50

	after(function ()
	{
		process.exitCode = 0
	});


	afterEach(function ()
	{
		process.exitCode = 0
	});

https://github.com/bluelovers/node-segment/blob/a4019ffe3e53abbbf4775cf253aabe468812be5f/test/fixme.test.ts#L101-L116

			it(args[0], function ()
			{
				let actual = Segment.stringify(doSegment(args[0]));


				let expected = args[1];


				console.debug(actual);


				lazyMatchSynonym001(actual, expected, args[2]);


				process.exitCode = 0
			});


			process.exitCode = 0
		});
	});

but still get npm ERR! Exit status 1

@plroebuck
Copy link
Contributor

Yeah, that's not programmatically though... See here.

mocha.run(function(failures) {
  process.exitCode = 0;  // exit with zero status regardless of failures
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior
Projects
None yet
Development

No branches or pull requests

5 participants