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

Commit

Permalink
chore(Jest): setup migration (#659)
Browse files Browse the repository at this point in the history
* chore(Jest): functions + hierarchical-facets [PART-1] (#660)

* chore(Jest): SearchParameters [PART-2] (#661)

* chore(Jest): SearchResults [PART-3] (#662)

* chore(Jest): algoliasearch.helper [PART-4] (#663)

* chore(Jest): top level spec [PART-5] (#664)

* chore(Jest): integration [PART-6] (#665)

* chore(Jest): runner [PART-7] (#666)

* chore(Jest): cleanup [PART-8] (#667)
  • Loading branch information
samouss authored and Haroenv committed May 7, 2019
1 parent eeb85c8 commit 52ff5d9
Show file tree
Hide file tree
Showing 92 changed files with 4,051 additions and 3,023 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.10.0
8.9.0
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
language: node_js
before_install:
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.13.0
- export PATH=$HOME/.yarn/bin:$PATH
cache:
yarn: true
script:
- yarn test-ci
- yarn test:ci
- yarn doc
- yarn test:perf
branches:
only:
- master
Expand Down
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
testEnvironment: 'node',
testMatch: ['<rootDir>/test/spec/**/*.[jt]s?(x)']
};
5 changes: 5 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-env jest */

'use strict';

jest.setTimeout(15000);
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
"doc:publish": "yarn run doc && gh-pages -d documentation",
"doc:staging": "scripts/staging-doc.sh",
"readme:toc": "doctoc --notitle README.md --maxlevel 3",
"test-ci": "scripts/test-ci.sh",
"test": "scripts/test.sh",
"test:unit": "ONLY_UNIT=true scripts/test.sh",
"test-node": "clear && node test/run | tap-spec",
"test:watch": "onchange '{src,test}/**/*.js' 'index.js' -- npm run test-node",
"test:perf": "node ./test/perf/index.js",
"test:ci": "scripts/test-ci.sh",
"test:unit": "jest",
"test:watch": "jest --watch",
"release": "git checkout dist/ && rm -rf node_modules && yarn && ./scripts/release.js",
"changelog:view-last": "conventional-changelog -u -n scripts/conventional-changelog/",
"changelog:update": "conventional-changelog -i CHANGELOG -s -u -n scripts/conventional-changelog/"
Expand All @@ -48,17 +46,13 @@
"babel-core": "6.26.3",
"babel-loader": "6.4.1",
"babel-preset-es2015": "6.24.1",
"bench": "0.3.6",
"benchmark": "2.1.4",
"browserify": "14.5.0",
"browzers": "1.3.0",
"bulk-require": "1.0.1",
"bulkify": "1.4.2",
"collect-json": "1.0.8",
"colors": "1.1.2",
"conventional-changelog-cli": "1.3.2",
"doctoc": "1.3.0",
"download": "5.0.3",
"envify": "4.1.0",
"eslint": "1.10.3",
"eslint-config-airbnb": "0.0.8",
Expand All @@ -71,6 +65,7 @@
"gulp-sass": "2.3.2",
"handlebars": "4.1.0",
"http-server": "0.11.1",
"jest": "24.7.1",
"jsdoc-parse": "1.2.7",
"jsdoc-to-markdown": "1.3.9",
"marked": "0.3.19",
Expand Down Expand Up @@ -98,10 +93,7 @@
"rimraf": "2.6.3",
"semver": "5.3.0",
"shelljs": "0.7.8",
"sinon": "4.5.0",
"st": "1.2.2",
"tap-spec": "4.1.1",
"tape": "4.9.0",
"uglify-js": "2.8.29",
"vinyl": "1.2.0",
"watchify": "3.7.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ if [ $CI == 'true' ]; then
set -x # debug messages
fi

node test/run.js | tap-spec
node test/run.js
12 changes: 10 additions & 2 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"rules": {
// in tests quotes are used for results objects, let's ignore badly formatted quotes
"quote-props": [2, "consistent"],
"quote-props": [
2,
"consistent"
]
},
"env": {
"jest": true
},
"globals": {
"test": true
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var SearchParameters = require('../../src/SearchParameters');
var SearchParameters = require('../../../src/SearchParameters');

module.exports = getData;

Expand Down
56 changes: 37 additions & 19 deletions test/integration-spec/helper.derive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ var setup = utils.setup;

var algoliasearchHelper = require('../../');

var test = require('tape');
var bind = require('lodash/bind');
var random = require('lodash/random');

if (!utils.shouldRun) {
test = test.skip;
}
var indexName = '_travis-algoliasearch-helper-js-' +
(process.env.TRAVIS_BUILD_NUMBER || 'DEV') +
'helper_searchonce' + random(0, 5000);

test(
'[INT][DERIVE] Query the same index twice with different query',
function(t) {
t.plan(5);
function() {
var indexName = '_travis-algoliasearch-helper-js-' +
(process.env.TRAVIS_BUILD_NUMBER || 'DEV') +
'helper_distinct.facet' + random(0, 5000);

setup(indexName, function(client, index) {
return setup(indexName, function(client, index) {
return index.addObjects([
{objectID: '0', content: 'tata'},
{objectID: '1', content: 'toto'}
Expand All @@ -32,7 +29,7 @@ test(
return client;
});
}).then(function(client) {
var helper = algoliasearchHelper(
var mainHelper = algoliasearchHelper(
client,
indexName,
{
Expand All @@ -44,21 +41,42 @@ test(
}]
}
);
var helper2 = helper.derive(function(state) {

var derivedHelper = mainHelper.derive(function(state) {
return state.setQuery('toto');
});

helper.on('result', function(results, state) {
t.equal(state.query, '', 'No query should be used for this query');
t.equal(results.hits.length, 2, 'Should retrieve all the records');
var mainResponse = new Promise(function(resolve) {
mainHelper.on('result', function(results, state) {
resolve({
results: results,
state: state
});
});
});

helper2.on('result', function(results, state) {
t.equal(state.query, 'toto', 'The query `toto` should be used');
t.equal(results.hits.length, 1, 'Should retrieve one record');
t.equal(results.hits[0].objectID, '1', 'And it should be the record `1`');
var derivedResponse = new Promise(function(resolve) {
derivedHelper.on('result', function(results, state) {
resolve({
results: results,
state: state
});
});
});

helper.search();
}).then(null, bind(t.error, t));
mainHelper.search();

return Promise.all([mainResponse, derivedResponse]);
}).then(function(responses) {
var mainResponse = responses[0];

expect(mainResponse.state.query).toBe('');
expect(mainResponse.results.hits.length).toBe(2);

var derivedResponse = responses[1];

expect(derivedResponse.state.query).toBe('toto');
expect(derivedResponse.results.hits.length).toBe(1);
expect(derivedResponse.results.hits[0].objectID).toBe('1');
});
});
39 changes: 17 additions & 22 deletions test/integration-spec/helper.distinct.facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ var setup = utils.setup;

var algoliasearchHelper = utils.isCIBrowser ? window.algoliasearchHelper : require('../../');

var test = require('tape');
var bind = require('lodash/bind');
var random = require('lodash/random');

if (!utils.shouldRun) {
test = test.skip;
}

test('[INT][FILTERS] Using distinct should let me retrieve all facet without distinct', function(t) {
test('[INT][FILTERS] Using distinct should let me retrieve all facet without distinct', function(done) {
var indexName = '_travis-algoliasearch-helper-js-' +
(process.env.TRAVIS_BUILD_NUMBER || 'DEV') +
'helper_distinct.facet' + random(0, 5000);
Expand Down Expand Up @@ -41,31 +39,28 @@ test('[INT][FILTERS] Using distinct should let me retrieve all facet without dis
facets: ['colors']
});

var calls = 0;
helper.on('error', function(err) {
t.fail(err);
t.end();
done.fail(err);
});

helper.on('result', function(content) {
calls++;
expect(content.hits.length).toBe(1);
expect(content.facets[0].data).toEqual({
blue: 2,
red: 2,
gold: 1,
green: 1
});

if (calls === 1) {
t.equal(content.hits.length, 1);
t.deepEqual(content.facets[0].data, {
blue: 2,
red: 2,
gold: 1,
green: 1
});
client.deleteIndex(indexName);
if (!process.browser) {
client.destroy();
}
t.end();
client.deleteIndex(indexName);

if (!process.browser) {
client.destroy();
}

done();
});

helper.setQueryParameter('distinct', true).search();
})
.then(null, bind(t.error, t));
});
});
35 changes: 19 additions & 16 deletions test/integration-spec/helper.filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ var setup = utils.setup;

var algoliasearchHelper = utils.isCIBrowser ? window.algoliasearchHelper : require('../../');

var test = require('tape');
var bind = require('lodash/bind');
var random = require('lodash/random');

if (!utils.shouldRun) {
test = test.skip;
}

test('[INT][FILTERS] Should retrieve different values for multi facetted records', function(t) {
test('[INT][FILTERS] Should retrieve different values for multi facetted records', function(done) {
var indexName = '_travis-algoliasearch-helper-js-' +
(process.env.TRAVIS_BUILD_NUMBER || 'DEV') +
'helper_refinements' + random(0, 5000);
Expand Down Expand Up @@ -41,16 +39,17 @@ test('[INT][FILTERS] Should retrieve different values for multi facetted records
});

var calls = 0;

helper.on('error', function(err) {
t.fail(err);
t.end();
done.fail(err);
});

helper.on('result', function(content) {
calls++;

if (calls === 1) {
t.equal(content.hits.length, 2, 'filter should result in two items');
t.deepEqual(content.facets[0].data, {
expect(content.hits.length).toBe(2);
expect(content.facets[0].data).toEqual({
f1: 2,
f2: 1,
f3: 1
Expand All @@ -60,35 +59,39 @@ test('[INT][FILTERS] Should retrieve different values for multi facetted records
}

if (calls === 2) {
t.equal(content.hits.length, 1, 'filter should result in one item');
t.deepEqual(content.facets[0].data, {
expect(content.hits.length).toBe(1);
expect(content.facets[0].data).toEqual({
f1: 1,
f2: 1
});

helper.toggleRefine('facet', 'f3').search();
}

if (calls === 3) {
t.equal(content.hits.length, 0, 'filter should result in 0 item');
t.equal(content.facets[0], undefined);
expect(content.hits.length).toBe(0);
expect(content.facets[0]).toBe(undefined);

helper.removeRefine('facet', 'f2').search();
}

if (calls === 4) {
t.equal(content.hits.length, 1, 'filter should result in one item again');
t.deepEqual(content.facets[0].data, {
expect(content.hits.length).toBe(1);
expect(content.facets[0].data).toEqual({
f1: 1,
f3: 1
});

client.deleteIndex(indexName);

if (!process.browser) {
client.destroy();
}
t.end();

done();
}
});

helper.addRefine('facet', 'f1').search();
})
.then(null, bind(t.error, t));
});
});
Loading

0 comments on commit 52ff5d9

Please sign in to comment.