Skip to content
Permalink
Browse files
feat(jasmine): Serenity reporter for Jasmine
  • Loading branch information
jan-molak committed May 14, 2019
1 parent 74ee480 commit afff01a83b5b38bd193d1cbe22a660e70bfa44b5
Showing with 2,312 additions and 3 deletions.
  1. +1 −0 documentation/website/package.json
  2. +7 −0 integration/jasmine/.gitignore
  3. +21 −0 integration/jasmine/examples/custom-reporter-requirements/jasmine_exclusions.js
  4. +21 −0 integration/jasmine/examples/custom-reporter-requirements/jasmine_failure_types.js
  5. +9 −0 integration/jasmine/examples/failing/assertion-fails.spec.js
  6. +9 −0 integration/jasmine/examples/failing/error-thrown.spec.js
  7. +9 −0 integration/jasmine/examples/failing/marked-as-failing.spec.js
  8. +13 −0 integration/jasmine/examples/failing/multiple-failures.spec.js
  9. +9 −0 integration/jasmine/examples/location.spec.js
  10. +9 −0 integration/jasmine/examples/passing.spec.js
  11. +9 −0 integration/jasmine/examples/pending/marked-as-pending-with-reason.spec.js
  12. +8 −0 integration/jasmine/examples/pending/marked-as-pending-xdescribe.spec.js
  13. +8 −0 integration/jasmine/examples/pending/marked-as-pending-xit.spec.js
  14. +7 −0 integration/jasmine/examples/pending/missing-implementation.spec.js
  15. +8 −0 integration/jasmine/examples/setup.js
  16. +39 −0 integration/jasmine/package.json
  17. +81 −0 integration/jasmine/spec/custom_reporter.spec.ts
  18. +57 −0 integration/jasmine/spec/detecting_file_system_location.spec.ts
  19. +122 −0 integration/jasmine/spec/failing_scenarios.spec.ts
  20. +25 −0 integration/jasmine/spec/passing_scenario.spec.ts
  21. +91 −0 integration/jasmine/spec/pending_scenarios.spec.ts
  22. +33 −0 integration/jasmine/src/jasmine.ts
  23. +10 −0 integration/jasmine/tsconfig-lint.json
  24. +13 −0 integration/jasmine/tsconfig.json
  25. +4 −0 packages/core/src/events/TestRunFinished.ts
  26. +24 −0 packages/core/src/events/TestSuiteFinished.ts
  27. +21 −0 packages/core/src/events/TestSuiteStarts.ts
  28. +2 −0 packages/core/src/events/index.ts
  29. +15 −0 packages/core/src/io/ErrorStackParser.ts
  30. +1 −0 packages/core/src/io/index.ts
  31. +22 −0 packages/core/src/model/TestSuiteDetails.ts
  32. +1 −0 packages/core/src/model/index.ts
  33. +4 −3 packages/core/src/stage/crew/serenity-bdd-reporter/reports/ErrorRenderer.ts
  34. +1 −0 packages/jasmine/.esdoc.js
  35. +9 −0 packages/jasmine/.gitignore
  36. +14 −0 packages/jasmine/.npmignore
  37. +201 −0 packages/jasmine/LICENSE.md
  38. +1 −0 packages/jasmine/NOTICE.md
  39. +26 −0 packages/jasmine/README.md
  40. +78 −0 packages/jasmine/package.json
  41. +708 −0 packages/jasmine/spec/SerenityReporterForJasmine.spec.ts
  42. +66 −0 packages/jasmine/spec/monkeyPatched.spec.ts
  43. +190 −0 packages/jasmine/src/SerenityReporterForJasmine.ts
  44. +28 −0 packages/jasmine/src/bootstrap.ts
  45. +3 −0 packages/jasmine/src/index.ts
  46. +24 −0 packages/jasmine/src/jasmine/Expectation.ts
  47. +27 −0 packages/jasmine/src/jasmine/JasmineDoneInfo.ts
  48. +17 −0 packages/jasmine/src/jasmine/JasmineStartedInfo.ts
  49. +11 −0 packages/jasmine/src/jasmine/Location.ts
  50. +11 −0 packages/jasmine/src/jasmine/Order.ts
  51. +25 −0 packages/jasmine/src/jasmine/Result.ts
  52. +33 −0 packages/jasmine/src/jasmine/SpecResult.ts
  53. +32 −0 packages/jasmine/src/jasmine/SuiteResult.ts
  54. +6 −0 packages/jasmine/src/jasmine/index.ts
  55. +56 −0 packages/jasmine/src/mokeyPatched.ts
  56. +10 −0 packages/jasmine/tsconfig-lint.json
  57. +22 −0 packages/jasmine/tsconfig.json
@@ -39,6 +39,7 @@
"@serenity-js/assertions": "2.0.1-alpha.64",
"@serenity-js/core": "2.0.1-alpha.64",
"@serenity-js/cucumber": "2.0.1-alpha.64",
"@serenity-js/jasmine": "2.0.1-alpha.64",
"@serenity-js/local-server": "2.0.1-alpha.64",
"@serenity-js/protractor": "2.0.1-alpha.64",
"@serenity-js/rest": "2.0.1-alpha.64",
@@ -0,0 +1,7 @@
# Node
node_modules
*.log

# Build artifacts
.nyc_output
lib
@@ -0,0 +1,21 @@
describe('excluded suite', function () {
it('will be excluded', function () {
expect(1).toBe(2);
});
});

fdescribe('focused suite, excludes other suites and specs', function () {
xdescribe('pending suite', function () {
it('will be pending', function () {
expect(2).toBe(1);
});
});

xit('pending spec', function () {
expect(2).toBe(4);
});

it('spec', function () {
expect(1).toBe(1);
});
});
@@ -0,0 +1,21 @@
beforeAll(function () {
fail('beforeAll')
});

afterAll(function () {
fail('afterAll');
});

describe('a suite', function () {
beforeAll(function () {
fail('suite beforeAll');
});

afterAll(function () {
fail('suite afterAll');
});

it('a spec', function () {
fail('spec');
});
});
@@ -0,0 +1,9 @@
describe('Jasmine', () => {

describe('A scenario', () => {

it('fails when the assertion fails', () => {
expect(false).toEqual(true);
});
});
});
@@ -0,0 +1,9 @@
describe('Jasmine', () => {

describe('A scenario', () => {

it('fails when an error is thrown', () => {
throw new Error(`Something happened`); // fail with throw
});
});
});
@@ -0,0 +1,9 @@
describe('Jasmine', () => {

describe('A scenario', () => {

it('fails when marked as failed', () => {
fail(`Something happened`);
});
});
});
@@ -0,0 +1,13 @@
describe('Jasmine', () => {

describe('A scenario', () => {

it('can fail with multiple failures', () => {
expect(true).toEqual(true);

fail(`first issue`);
fail(`second issue`);
expect(false).toEqual(true);
});
});
});
@@ -0,0 +1,9 @@
describe('Jasmine', () => {

describe('Detecting file system location', () => {

it('works for both the suites and the individual specs', () => {
// no-op
});
});
});
@@ -0,0 +1,9 @@
describe('Jasmine', () => {

describe('A scenario', () => {

it('passes', () => {
expect(true).toBe(true);
});
});
});
@@ -0,0 +1,9 @@
describe('Jasmine', () => {

describe('A scenario', () => {

it(`is marked as pending`, () => {
pending('implementation missing');
});
});
});
@@ -0,0 +1,8 @@
describe('Jasmine', () => {

xdescribe('A scenario', () => {

it(`is marked as pending`, () => {
});
});
});
@@ -0,0 +1,8 @@
describe('Jasmine', () => {

describe('A scenario', () => {

xit(`is marked as pending`, () => {
});
});
});
@@ -0,0 +1,7 @@
describe('Jasmine', () => {

describe('A scenario', () => {

it(`is marked as pending when it hasn't been implemented yet`);
});
});
@@ -0,0 +1,8 @@
const
{ ChildProcessReporter } = require('@integration/testing-tools'),
{ serenity, DebugReporter } = require('@serenity-js/core');

serenity.setTheStage(
new ChildProcessReporter(),
new DebugReporter(),
);
@@ -0,0 +1,39 @@
{
"name": "@integration/jasmine",
"version": "2.0.1-alpha.64",
"description": "Jasmine integration tests",
"author": {
"name": "Jan Molak",
"email": "jan.molak@smartcodeltd.co.uk",
"url": "https://janmolak.com"
},
"homepage": "http://serenity-js.org",
"license": "Apache-2.0",
"private": true,
"config": {
"access": "private"
},
"scripts": {
"clean": "rimraf lib",
"lint": "tslint --project tsconfig-lint.json --config ../../tslint.json --format stylish",
"test": "parallel-mocha --opts ../../mocha.opts 'spec/**/*.spec.*'",
"test:parallel": "mocha-parallel-tests --opts ../../mocha.opts 'spec/**/*.spec.*'"
},
"repository": {
"type": "git",
"url": "https://github.com/jan-molak/serenity-js.git"
},
"bugs": {
"url": "https://github.com/jan-molak/serenity-js/issues"
},
"engines": {
"node": ">= 6.9.x",
"npm": ">= 3"
},
"dependencies": {
"@integration/testing-tools": "2.0.1-alpha.64",
"@serenity-js/core": "2.0.1-alpha.64",
"@serenity-js/jasmine": "2.0.1-alpha.64",
"jasmine": "^3.4.0"
}
}
@@ -0,0 +1,81 @@
import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { SceneFinished, SceneStarts, SceneTagged, TestRunnerDetected, TestSuiteFinished, TestSuiteStarts } from '@serenity-js/core/lib/events';
import { ExecutionFailedWithError, ExecutionSkipped, ExecutionSuccessful, FeatureTag, ImplementationPending, Name, ProblemIndication } from '@serenity-js/core/lib/model';
import 'mocha';
import { jasmine } from '../src/jasmine';

describe('@serenity-js/jasmine', function () {

this.timeout(5000);

/**
* @see https://jasmine.github.io/tutorials/custom_reporter
*/
describe('to meet the requirements for custom reporters', () => {

/**
* @see https://jasmine.github.io/examples/jasmine_failure_types.js
*/
it('recognises "all the possible" failure modes', () =>
jasmine(
'examples/custom-reporter-requirements/jasmine_failure_types.js',
'--random=false',
)
.then(ifExitCodeIsOtherThan(1, logOutput))
.then(res => {

expect(res.exitCode).to.equal(1);

PickEvent.from(res.events)
.next(TestSuiteStarts, event => expect(event.value.name).to.equal(new Name(`a suite`)))
.next(SceneStarts, event => expect(event.value.name).to.equal(new Name(`a spec`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('a suite')))
.next(TestRunnerDetected, event => expect(event.value).to.equal(new Name('Jasmine')))
.next(SceneFinished, event => {
const outcome = event.outcome as ProblemIndication;
expect(outcome).to.be.instanceOf(ExecutionFailedWithError);

expect(outcome.error).to.be.instanceof(Error);
expect(outcome.error.message).to.equal('Failed: spec'); // there's no message when the spec body is missing
})
.next(TestSuiteFinished, event => {
expect(event.value.name).to.equal(new Name(`a suite`));
expect(event.outcome).to.be.instanceof(ExecutionFailedWithError);
expect((event.outcome as ExecutionFailedWithError).error.message).to.equal('Failed: suite beforeAll');
})
;
}));

/**
* @see https://jasmine.github.io/examples/jasmine_exclusions.js
*/
it('recognises the pending, excluded and skipped scenarios', () =>
jasmine(
'examples/custom-reporter-requirements/jasmine_exclusions.js',
'--random=false',
)
.then(ifExitCodeIsOtherThan(1, logOutput))
.then(res => {

expect(res.exitCode).to.equal(1);

PickEvent.from(res.events)
.next(SceneStarts, event => expect(event.value.name).to.equal(new Name(`pending suite will be pending`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag(`focused suite, excludes other suites and specs`)))
.next(SceneFinished, event => expect(event.outcome).to.be.instanceof(ImplementationPending))

.next(SceneStarts, event => expect(event.value.name).to.equal(new Name(`pending spec`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag(`focused suite, excludes other suites and specs`)))
.next(SceneFinished, event => expect(event.outcome).to.be.instanceof(ImplementationPending))

.next(SceneStarts, event => expect(event.value.name).to.equal(new Name(`spec`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag(`focused suite, excludes other suites and specs`)))
.next(SceneFinished, event => expect(event.outcome).to.be.instanceof(ExecutionSuccessful))

.next(SceneStarts, event => expect(event.value.name).to.equal(new Name(`will be excluded`)))
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag(`excluded suite`)))
.next(SceneFinished, event => expect(event.outcome).to.be.instanceof(ExecutionSkipped))
;
}));
});
});
@@ -0,0 +1,57 @@
import 'mocha';

import { expect, ifExitCodeIsOtherThan, logOutput, PickEvent } from '@integration/testing-tools';
import { SceneFinished, SceneStarts, TestSuiteFinished, TestSuiteStarts } from '@serenity-js/core/lib/events';
import { Name } from '@serenity-js/core/lib/model';
import { jasmine } from '../src/jasmine';

describe('@serenity-js/jasmine', function () {

this.timeout(5000);

it('detects the filesystem location of a test suite and individual specs', () => jasmine('examples/location.spec.js')
.then(ifExitCodeIsOtherThan(0, logOutput))
.then(res => {

expect(res.exitCode).to.equal(0);

PickEvent.from(res.events)
.next(TestSuiteStarts, event => {
expect(event.value.name).to.equal(new Name('Jasmine'));
expect(event.value.location.path.value).to.match(/location.spec.js$/);
expect(event.value.location.line).to.equal(1);
// expect(event.value.location.column).to.equal(1);
})
.next(TestSuiteStarts, event => {
expect(event.value.name).to.equal(new Name('Detecting file system location'));
expect(event.value.location.path.value).to.match(/location.spec.js$/);
expect(event.value.location.line).to.equal(3);
expect(event.value.location.column).to.equal(5);
})
.next(SceneStarts, event => {
expect(event.value.name).to.equal(new Name('Detecting file system location works for both the suites and the individual specs'));
expect(event.value.location.path.value).to.match(/location.spec.js$/);
expect(event.value.location.line).to.equal(5);
expect(event.value.location.column).to.equal(9);
})
.next(SceneFinished, event => {
expect(event.value.name).to.equal(new Name('Detecting file system location works for both the suites and the individual specs'));
expect(event.value.location.path.value).to.match(/location.spec.js$/);
expect(event.value.location.line).to.equal(5);
expect(event.value.location.column).to.equal(9);
})
.next(TestSuiteFinished, event => {
expect(event.value.name).to.equal(new Name('Detecting file system location'));
expect(event.value.location.path.value).to.match(/location.spec.js$/);
expect(event.value.location.line).to.equal(3);
expect(event.value.location.column).to.equal(5);
})
.next(TestSuiteFinished, event => {
expect(event.value.name).to.equal(new Name('Jasmine'));
expect(event.value.location.path.value).to.match(/location.spec.js$/);
expect(event.value.location.line).to.equal(1);
// expect(event.value.location.column).to.equal(1);
})
;
}));
});

0 comments on commit afff01a

Please sign in to comment.