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

test(helper): integrate unit and integration tests into main jest configuration #5770

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,10 @@ const config = {
},
},
{
files: ['packages/algoliasearch-helper/test/**/*.js'],
files: [
'packages/algoliasearch-helper/__tests__/**/*.js',
'packages/algoliasearch-helper/test/**/*.js',
],
rules: {
'no-console': 'off',
'jest/no-done-callback': 'off',
Expand Down
10 changes: 8 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
// @ts-check

const enableIntegrationTest =
process.env.ONLY_UNIT !== 'true' &&
process.env.INTEGRATION_TEST_API_KEY &&
process.env.INTEGRATION_TEST_APPID;

/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
rootDir: process.cwd(),
testRunner: 'jest-circus',
testEnvironment: 'node',
setupFilesAfterEnv: ['./tests/utils/setupTests.ts'],
globalTeardown: './tests/utils/teardownTests.ts',
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/packages/*/node_modules/',
'<rootDir>/packages/*/dist*',
'<rootDir>/tests/e2e/*',
'<rootDir>/examples/',
'<rootDir>/packages/algoliasearch-helper',
'<rootDir>/packages/create-instantsearch-app',
'<rootDir>/packages/react-instantsearch-hooks-router-nextjs',
'/__utils__/',
],
enableIntegrationTest ? '' : '/integration-spec/',
].filter(Boolean),
watchPathIgnorePatterns: [
'<rootDir>/packages/*/cjs',
'<rootDir>/packages/*/dist',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test:e2e": "yarn test:e2e:local",
"test:e2e:local": "wdio scripts/wdio/local.conf.js",
"test:e2e:saucelabs": "wdio scripts/wdio/saucelabs.conf.js",
"test:v3": "lerna run test:v3",
"test:v3": "./scripts/retry.sh 3 'jest --maxWorkers=4 --ci' && lerna run test:v3 --concurrency=1",
"release": "shipjs prepare",
"prepare": "lerna run prepare && patch-package",
"prepare-vue3": "./scripts/prepare-vue3.js"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var utils = require('../integration-utils');
jest.retryTimes(3, { logErrorsBeforeRetry: true });

var utils = require('../../test/integration-utils');
var setup = utils.setupSimple;
var createIndexName = utils.createIndexName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var SearchResults = require('../../../src/SearchResults');

test('getFacetByName should return a given facet be it disjunctive or conjunctive', function () {
var data = require('../../datasets/SearchParameters/search.dataset')();
var data =
require('../../../test/datasets/SearchParameters/search.dataset')();

var result = new SearchResults(data.searchParams, data.response.results);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var algoliaSearch = require('algoliasearch');
var algoliasearchHelper = require('../../../index');

test('When searchOnce with callback, hasPendingRequests is true', function (done) {
var testData = require('../../datasets/SearchParameters/search.dataset')();
var testData =
require('../../../test/datasets/SearchParameters/search.dataset')();
var client = algoliaSearch('dsf', 'dsfdf');

var triggerCb;
Expand Down Expand Up @@ -38,7 +39,8 @@ test('When searchOnce with callback, hasPendingRequests is true', function (done
});

test('When searchOnce with promises, hasPendingRequests is true', function (done) {
var testData = require('../../datasets/SearchParameters/search.dataset')();
var testData =
require('../../../test/datasets/SearchParameters/search.dataset')();
var client = algoliaSearch('dsf', 'dsfdf');

var triggerCb;
Expand Down Expand Up @@ -109,7 +111,8 @@ test('When searchForFacetValues, hasPendingRequests is true', function (done) {
});

test('When helper.search(), hasPendingRequests is true', function (done) {
var testData = require('../../datasets/SearchParameters/search.dataset')();
var testData =
require('../../../test/datasets/SearchParameters/search.dataset')();
var client = algoliaSearch('dsf', 'dsfdf');

var triggerCb;
Expand Down Expand Up @@ -144,7 +147,8 @@ test('When helper.search(), hasPendingRequests is true', function (done) {
});

test('When helper.search() and one request is discarded, hasPendingRequests is true unless all come back', function (done) {
var testData = require('../../datasets/SearchParameters/search.dataset')();
var testData =
require('../../../test/datasets/SearchParameters/search.dataset')();
var client = algoliaSearch('dsf', 'dsfdf');

var triggerCbs = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test('the queryid should keep increasing when new requests arrives', function ()
});

test('the response handler should check that the query is not outdated', function (done) {
var testData = require('../../datasets/SearchParameters/search.dataset')();
var testData =
require('../../../test/datasets/SearchParameters/search.dataset')();
var shouldTriggerResult = true;
var callCount = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var SearchParameters = require('../../../src/SearchParameters');
var algoliasearchHelper = require('../../../index');

test('searchOnce should call the algolia client according to the number of refinements and call callback with no error and with results when no error', function (done) {
var testData = require('../../datasets/SearchParameters/search.dataset')();
var testData =
require('../../../test/datasets/SearchParameters/search.dataset')();

var client = {
search: jest.fn().mockImplementationOnce(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var SearchParameters = require('../../src/SearchParameters');
var getQueries = requestBuilder._getQueries;

test('The request builder should set analytics to subsequent queries', function () {
var testData = require('../datasets/SearchParameters/search.dataset')();
var testData =
require('../../test/datasets/SearchParameters/search.dataset')();
var searchParams = testData.searchParams;

searchParams.analytics = true;
Expand All @@ -17,7 +18,8 @@ test('The request builder should set analytics to subsequent queries', function
});

test('The request builder should set clickAnalytics to subsequent queries', function () {
var testData = require('../datasets/SearchParameters/search.dataset')();
var testData =
require('../../test/datasets/SearchParameters/search.dataset')();
var searchParams = testData.searchParams;

searchParams.clickAnalytics = true;
Expand All @@ -29,7 +31,8 @@ test('The request builder should set clickAnalytics to subsequent queries', func
});

test('The request builder should should force analytics to false on subsequent queries if not specified', function () {
var testData = require('../datasets/SearchParameters/search.dataset')();
var testData =
require('../../test/datasets/SearchParameters/search.dataset')();
var searchParams = testData.searchParams;

var queries = getQueries(searchParams.index, searchParams);
Expand All @@ -39,7 +42,8 @@ test('The request builder should should force analytics to false on subsequent q
});

test('The request builder should should force clickAnalytics to false on subsequent queries if not specified', function () {
var testData = require('../datasets/SearchParameters/search.dataset')();
var testData =
require('../../test/datasets/SearchParameters/search.dataset')();
var searchParams = testData.searchParams;

var queries = getQueries(searchParams.index, searchParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var algoliasearchHelper = require('../../index');

test('Search should call the algolia client according to the number of refinements', function (done) {
var testData = require('../datasets/SearchParameters/search.dataset')();
var testData =
require('../../test/datasets/SearchParameters/search.dataset')();

var client = {
search: jest.fn().mockImplementationOnce(function () {
Expand Down Expand Up @@ -90,7 +91,8 @@ test('Search should call the algolia client according to the number of refinemen
});

test('Search should not mutate the original client response', function (done) {
var testData = require('../datasets/SearchParameters/search.dataset')();
var testData =
require('../../test/datasets/SearchParameters/search.dataset')();

var client = {
search: jest.fn().mockImplementationOnce(function () {
Expand Down
10 changes: 0 additions & 10 deletions packages/algoliasearch-helper/jest.config.js

This file was deleted.

5 changes: 0 additions & 5 deletions packages/algoliasearch-helper/jest.setup.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/algoliasearch-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"build": "./scripts/build.sh",
"lint": "eslint .",
"doc": "node documentation-src/metalsmith.js",
"test": "../../scripts/retry.sh 3 'scripts/test.sh'",
"test:unit": "jest",
"test:watch": "jest --watch",
"test:v3": "yarn run test",
"version": "./scripts/update-version.js"
},
"author": {
Expand Down
11 changes: 0 additions & 11 deletions packages/algoliasearch-helper/scripts/test.sh

This file was deleted.

7 changes: 7 additions & 0 deletions packages/algoliasearch-helper/test/integration-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ function setup(indexName, fn) {
var appID = process.env.INTEGRATION_TEST_APPID;
var key = process.env.INTEGRATION_TEST_API_KEY;

if (!appID) {
throw new Error('Missing environment variable INTEGRATION_TEST_APPID');
}
if (!key) {
throw new Error('Missing environment variable INTEGRATION_TEST_API_KEY');
}

var client = algoliasearch(appID, key, {
// all indexing requests must be done in https
protocol: 'https:',
Expand Down
52 changes: 0 additions & 52 deletions packages/algoliasearch-helper/test/run.js

This file was deleted.

Loading