Skip to content

Commit 3b9b997

Browse files
Prepare using setup.js as the main entrypoint for tests (#426)
* Prepare using setup.js as the main entrypoint for tests
1 parent 0c64356 commit 3b9b997

13 files changed

+39
-18
lines changed

.mocharc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"recursive": true,
3+
"retries": 3
4+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"types": "types",
5858
"scripts": {
5959
"test": "tools/scripts/test.sh",
60-
"test:unit": "mocha --recursive test/unit",
60+
"test:unit": "tools/scripts/test.es6.unit.sh",
6161
"test-with-temp-cloud": "tools/scripts/tests-with-temp-cloud.sh",
6262
"dtslint": "tools/scripts/ditslint.sh",
6363
"lint": "tools/scripts/lint.sh",

test/integration/api/admin/api_spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ function findByAttr(elements, attr, value) {
141141

142142

143143
describe("api", function () {
144-
this.retries(3);
145144
var contextKey = `test-key${UNIQUE_JOB_SUFFIX_ID}`;
146145
before("Verify Configuration", function () {
147146
let config = cloudinary.config(true);

test/integration/api/search/search_spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const SEARCH_TAG = 'npm_advanced_search_' + UNIQUE_JOB_SUFFIX_ID;
2424

2525

2626
describe("search_api", function () {
27-
this.retries(3);
2827
describe("unit", function () {
2928
it('should create empty json', function () {
3029
var query_hash = cloudinary.v2.search.instance().to_query();

test/integration/api/uploader/archivespec.js

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ sharedExamples('archive', function () {
8585
});
8686

8787
describe("archive", function () {
88-
this.retries(3);
8988
includeContext('archive');
9089
describe("utils", function () {
9190
describe('.generate_zip_download_url', function () {

test/integration/api/uploader/uploader_spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const {
4040
require('jsdom-global')();
4141

4242
describe("uploader", function () {
43-
this.retries(3);
4443
before("Verify Configuration", function () {
4544
var config = cloudinary.config(true);
4645
if (!(config.api_key && config.api_secret)) {

test/streaming_profiles_spec.js test/integration/streaming_profiles_spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const keys = require('lodash/keys');
22
const Q = require('q');
3-
const cloudinary = require("../cloudinary");
4-
const helper = require("./spechelper");
5-
const TIMEOUT = require('./testUtils/testConstants').TIMEOUT;
3+
const cloudinary = require("../../cloudinary");
4+
const helper = require("../spechelper");
5+
const TIMEOUT = require('../testUtils/testConstants').TIMEOUT;
66
const api = cloudinary.v2.api;
77

88
describe('Cloudinary::Api', function () {

test/mocha.opts

-3
This file was deleted.

test/setup.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
global.expect = require('expect.js');
2-
require('./testUtils/testBootstrap');
3-
4-
51
require('dotenv').load({
62
silent: true
73
});
84

5+
if (!process.env.CLOUDINARY_URL) {
6+
throw 'Could not start tests - Cloudianry URL is undefined'
7+
}
98

9+
global.expect = require('expect.js');
10+
require('./testUtils/testBootstrap');

test/testUtils/testConstants.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
require('dotenv').load({
2+
silent: true
3+
});
14
const UNIQUE_JOB_SUFFIX_ID = process.env.TRAVIS_JOB_ID || Math.floor(Math.random() * 999999);
25

36
// create public ID string for tests

tools/scripts/test.es5.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
#!/bin/bash
2-
mocha --recursive --require 'babel-register' --require 'babel-polyfill' test/
2+
3+
# --File ensures that setup.js runs first
4+
# This file should be in the config under a 'require' key
5+
# However Mocha 6 does not expose before, beforeEach after etc. at that time
6+
# When Removing support of Node 6 and 8 and using Mocha 8, we should move this to the mocharc.json file
7+
mocha --require './test/setup.js' --require 'babel-register' --require 'babel-polyfill' "./test/**/*spec.js"

tools/scripts/test.es6.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ done
1212

1313
if [ "$COLLECT_COVERAGE" -eq "1" ]; then
1414
echo 'Running code coverage test on ES6 code'
15-
nyc --reporter=html mocha --recursive test/
15+
16+
# --File ensures that setup.js runs first
17+
# This file should be in the config under a 'require' key
18+
# However Mocha 6 does not expose before, beforeEach after etc. at that time
19+
# When Removing support of Node 6 and 8 and using Mocha 8, we should move this to the mocharc.json file
20+
nyc --reporter=html mocha --file "./test/setup.js" "./test/**/*spec.js"
1621
exit;
1722
else
1823
echo 'Running tests on ES6 Code'
19-
mocha --recursive test/
24+
25+
# --File ensures that setup.js runs first
26+
# This file should be in the config under a 'require' key
27+
# However Mocha 6 does not expose before, beforeEach after etc. at that time
28+
# When Removing support of Node 6 and 8 and using Mocha 8, we should move this to the mocharc.json file
29+
mocha --file "./test/setup.js" "./test/**/*spec.js"
2030
fi

tools/scripts/test.es6.unit.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# --File ensures that setup.js runs first
2+
# This file should be in the config under a 'require' key
3+
# However Mocha 6 does not expose before, beforeEach after etc. at that time
4+
# When Removing support of Node 6 and 8 and using Mocha 8, we should move this to the mocharc.json file
5+
mocha --file "./test/setup.js" "./test/unit/**/*spec.js"

0 commit comments

Comments
 (0)