Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
[#303] Add support for "BeforeAll()" and "afterAll()" methods (Jasmine)
Browse files Browse the repository at this point in the history
closes #303
  • Loading branch information
dsifford authored and HamletDRC committed Oct 24, 2016
1 parent f8af40e commit 0dec7b9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Rule Name | Description | Since
`missing-jsdoc` | All files must have a top level [JSDoc](http://usejsdoc.org/) comment. A JSDoc comment starts with /** (not one more or one less asterisk) and a JSDoc at the 'top-level' appears without leading spaces. Trailing spaces are acceptable but not recommended. | 1.0
`missing-optional-annotation` | Deprecated - This rule is now enforced by the TypeScript compiler. A parameter that follows one or more parameters marked as optional is not itself marked optional | 0.0.1
`mocha-avoid-only` | Do not invoke Mocha's describe.only, it.only or context.only functions. These functions are useful ways to run a single unit test or a single test case during your build, but please be careful to not push these methods calls to your version control repositiory because it will turn off any of the other tests.| 1.0
`mocha-no-side-effect-code` | All test logic in a Mocha test case should be within Mocha lifecycle method and not defined statically to execute when the module loads. Put all assignments and initialization statements in a before(), beforeEach(), after(), afterEach(), or it() function. Code executed outside of these lifecycle methods can throw exceptions before the test runner is initialized and can result in errors or even test runner crashes. This rule can be configured with a regex to ignore certain initializations. For example, to ignore any calls to `RestDataFactory` configure the rule with: `[true, { ignore: '^RestDataFactory\\..*' }]`| 2.0.10
`mocha-no-side-effect-code` | All test logic in a Mocha test case should be within Mocha lifecycle method and not defined statically to execute when the module loads. Put all assignments and initialization statements in a before(), beforeEach(), beforeAll(), after(), afterEach(), afterAll(), or it() function. Code executed outside of these lifecycle methods can throw exceptions before the test runner is initialized and can result in errors or even test runner crashes. This rule can be configured with a regex to ignore certain initializations. For example, to ignore any calls to `RestDataFactory` configure the rule with: `[true, { ignore: '^RestDataFactory\\..*' }]`| 2.0.10
`mocha-unneeded-done` | A function declares a MochaDone parameter but only resolves it synchronously in the main function. The MochaDone parameter can be safely removed from the parameter list.| 2.0.10
`no-backbone-get-set-outside-model` | Avoid using model.get('x') and model.set('x', value) Backbone accessors outside of the owning model. This breaks type safety and you should define getters and setters for your attributes instead.| 1.0
`no-banned-terms` | Do not use banned terms: [caller](https://msdn.microsoft.com/library/7t96kt3h(v=vs.94).aspx), [callee](https://msdn.microsoft.com/library/334e1zza(v=vs.94).aspx), [eval](https://msdn.microsoft.com/library/12k71sw7(v=vs.94).aspx), [arguments](https://msdn.microsoft.com/library/he95z461(v=vs.94).aspx). These terms refer to functions or properties that should not be used, so it is best practice to simply avoid them. | 0.0.1
Expand Down
4 changes: 2 additions & 2 deletions src/mochaNoSideEffectCodeRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class MochaNoSideEffectCodeRuleWalker extends ErrorTolerantWalker {
this.isInDescribe = false;
}
} else if (functionName === 'it'
|| functionName === 'before' || functionName === 'beforeEach'
|| functionName === 'after' || functionName === 'afterEach') {
|| functionName === 'before' || functionName === 'beforeEach' || functionName === 'beforeAll'
|| functionName === 'after' || functionName === 'afterEach' || functionName === 'afterAll') {
// variable initialization is allowed inside the lifecycle methods, so do not visit them
return;
} else if (this.isInDescribe) {
Expand Down
12 changes: 12 additions & 0 deletions src/tests/MochaNoSideEffectCodeRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ describe('mochaNoSideEffectCodeRule', () : void => {
beforeEach((): void => {
const foo = someValue();
});
beforeAll((): void => {
const foo = someValue();
});
after((): void => {
const foo = someValue();
});
afterEach((): void => {
const foo = someValue();
});
afterAll((): void => {
const foo = someValue();
});
it((): void => {
const foo = someValue();
});
Expand Down Expand Up @@ -148,12 +154,18 @@ describe('mochaNoSideEffectCodeRule', () : void => {
beforeEach((): void => {
const foo = someValue();
});
beforeAll((): void => {
const foo = someValue();
});
after((): void => {
const foo = someValue();
});
afterEach((): void => {
const foo = someValue();
});
afterAll((): void => {
const foo = someValue();
});
it((): void => {
const foo = someValue();
});
Expand Down

0 comments on commit 0dec7b9

Please sign in to comment.