Get all test fails from Mocha
up vote
0
down vote
favorite
So, I have about 600 tests made with Mocha and now I need to automatically run all of them and get all errors and success count to send this information to monitoring server.
I can make bash script, which runs tests and writes Mocha log to file, then parse this log file and get success count and fail logs (for example by grep), but this is too dirty solution.
I would prefer run tests programmatically and get from Mocha something like fail messages and success tests array to work around this, but I couldn't find any docs about this.
So, how to solve this problem?
javascript node.js testing mocha qa
add a comment |
up vote
0
down vote
favorite
So, I have about 600 tests made with Mocha and now I need to automatically run all of them and get all errors and success count to send this information to monitoring server.
I can make bash script, which runs tests and writes Mocha log to file, then parse this log file and get success count and fail logs (for example by grep), but this is too dirty solution.
I would prefer run tests programmatically and get from Mocha something like fail messages and success tests array to work around this, but I couldn't find any docs about this.
So, how to solve this problem?
javascript node.js testing mocha qa
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
So, I have about 600 tests made with Mocha and now I need to automatically run all of them and get all errors and success count to send this information to monitoring server.
I can make bash script, which runs tests and writes Mocha log to file, then parse this log file and get success count and fail logs (for example by grep), but this is too dirty solution.
I would prefer run tests programmatically and get from Mocha something like fail messages and success tests array to work around this, but I couldn't find any docs about this.
So, how to solve this problem?
javascript node.js testing mocha qa
So, I have about 600 tests made with Mocha and now I need to automatically run all of them and get all errors and success count to send this information to monitoring server.
I can make bash script, which runs tests and writes Mocha log to file, then parse this log file and get success count and fail logs (for example by grep), but this is too dirty solution.
I would prefer run tests programmatically and get from Mocha something like fail messages and success tests array to work around this, but I couldn't find any docs about this.
So, how to solve this problem?
javascript node.js testing mocha qa
javascript node.js testing mocha qa
asked Nov 8 at 11:17
J. Toming
196
196
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Create a file, let's say intercept-failures.js
with the following content:
const failures = ;
const successes = ;
afterEach(function () {
const title = this.currentTest.title;
const state = this.currentTest.state;
if (state === "passed") {
successes.push(title)
} else if (state === "failed") {
failures.push(title)
}
});
after(function () {
console.log("failures", failures);
console.log("successes", successes);
});
Add a flag --file intercept-failures.js
to your mocha invocation (for example mocha --file intercept-failures.js test/**
)
The afterEach
hook accumulates all test results, and then you can do something with them in the after
hook. The --file
flag just makes sure that the hooks are added to all test suites.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Create a file, let's say intercept-failures.js
with the following content:
const failures = ;
const successes = ;
afterEach(function () {
const title = this.currentTest.title;
const state = this.currentTest.state;
if (state === "passed") {
successes.push(title)
} else if (state === "failed") {
failures.push(title)
}
});
after(function () {
console.log("failures", failures);
console.log("successes", successes);
});
Add a flag --file intercept-failures.js
to your mocha invocation (for example mocha --file intercept-failures.js test/**
)
The afterEach
hook accumulates all test results, and then you can do something with them in the after
hook. The --file
flag just makes sure that the hooks are added to all test suites.
add a comment |
up vote
2
down vote
accepted
Create a file, let's say intercept-failures.js
with the following content:
const failures = ;
const successes = ;
afterEach(function () {
const title = this.currentTest.title;
const state = this.currentTest.state;
if (state === "passed") {
successes.push(title)
} else if (state === "failed") {
failures.push(title)
}
});
after(function () {
console.log("failures", failures);
console.log("successes", successes);
});
Add a flag --file intercept-failures.js
to your mocha invocation (for example mocha --file intercept-failures.js test/**
)
The afterEach
hook accumulates all test results, and then you can do something with them in the after
hook. The --file
flag just makes sure that the hooks are added to all test suites.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Create a file, let's say intercept-failures.js
with the following content:
const failures = ;
const successes = ;
afterEach(function () {
const title = this.currentTest.title;
const state = this.currentTest.state;
if (state === "passed") {
successes.push(title)
} else if (state === "failed") {
failures.push(title)
}
});
after(function () {
console.log("failures", failures);
console.log("successes", successes);
});
Add a flag --file intercept-failures.js
to your mocha invocation (for example mocha --file intercept-failures.js test/**
)
The afterEach
hook accumulates all test results, and then you can do something with them in the after
hook. The --file
flag just makes sure that the hooks are added to all test suites.
Create a file, let's say intercept-failures.js
with the following content:
const failures = ;
const successes = ;
afterEach(function () {
const title = this.currentTest.title;
const state = this.currentTest.state;
if (state === "passed") {
successes.push(title)
} else if (state === "failed") {
failures.push(title)
}
});
after(function () {
console.log("failures", failures);
console.log("successes", successes);
});
Add a flag --file intercept-failures.js
to your mocha invocation (for example mocha --file intercept-failures.js test/**
)
The afterEach
hook accumulates all test results, and then you can do something with them in the after
hook. The --file
flag just makes sure that the hooks are added to all test suites.
edited Nov 8 at 11:41
answered Nov 8 at 11:34
Laurynas Lubys
463
463
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206680%2fget-all-test-fails-from-mocha%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown