Skip to content

Commit a5f9505

Browse files
Haroenvdhayab
andauthored
chore(ci): make helper integration tests runnable (#6562)
* chore(ci): make helper integration tests runnable * boolean * hop * load integration env vars in test jobs * v4 * v4 * like this? --------- Co-authored-by: Dhaya <[email protected]>
1 parent 82990f0 commit a5f9505

File tree

12 files changed

+81
-21
lines changed

12 files changed

+81
-21
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ workflows:
4949
requires:
5050
- build
5151
- unit tests:
52+
context: fx-libraries
5253
requires:
5354
- build
5455
- legacy algoliasearch v3:
5556
requires:
5657
- build
5758
- legacy algoliasearch v4:
59+
context: fx-libraries
5860
requires:
5961
- build
6062
- vue v3:

packages/algoliasearch-helper/test/integration-spec/helper.distinct.facet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('[INT][FILTERS] Using distinct should let me retrieve all facet without dis
3232
});
3333

3434
helper.on('error', function (event) {
35-
done.fail(event.error);
35+
done(event.error);
3636
});
3737

3838
helper.on('result', function (event) {

packages/algoliasearch-helper/test/integration-spec/helper.filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('[INT][FILTERS] Should retrieve different values for multi facetted records
3333
var calls = 0;
3434

3535
helper.on('error', function (event) {
36-
done.fail(event.error);
36+
done(event.error);
3737
});
3838

3939
helper.on('result', function (event) {

packages/algoliasearch-helper/test/integration-spec/helper.numerics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('[INT][NUMERICS][RAW-API]Test numeric operations on the helper and their re
3333
var calls = 0;
3434

3535
helper.on('error', function (event) {
36-
done.fail(event.error);
36+
done(event.error);
3737
});
3838

3939
helper.on('result', function (event) {
@@ -85,7 +85,7 @@ test('[INT][NUMERICS][MANAGED-API]Test numeric operations on the helper and thei
8585
var calls = 0;
8686

8787
helper.on('error', function (event) {
88-
done.fail(event.error);
88+
done(event.error);
8989
});
9090

9191
helper.on('result', function (event) {

packages/algoliasearch-helper/test/integration-spec/helper.searchOnce.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ test('[INT][SEARCHONCE] Should be able to search once with custom parameters wit
3131

3232
var calls = 1;
3333
helper.on('error', function (event) {
34-
done.fail(event.error);
34+
done(event.error);
3535
});
3636

3737
helper.on('result', function (event) {
3838
if (calls === 3) {
3939
expect(event.results.hits.length).toBe(3);
4040
done();
4141
} else {
42-
done.fail('Should not trigger the result event until the third call');
42+
done(
43+
new Error('Should not trigger the result event until the third call')
44+
);
4345
}
4446
});
4547

packages/algoliasearch-helper/test/integration-spec/helper.tags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('[INT][TAGS]Test tags operations on the helper and their results on the alg
3333
var calls = 0;
3434

3535
helper.on('error', function (event) {
36-
done.fail(event.error);
36+
done(event.error);
3737
});
3838

3939
helper.on('result', function (event) {

packages/algoliasearch-helper/test/integration-utils.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,50 @@ function setup(indexName, fn) {
1111
// all indexing requests must be done in https
1212
protocol: 'https:',
1313
});
14-
client.deleteIndex =
15-
client.deleteIndex ||
16-
function (deleteIndexName) {
14+
var hasInitIndex = Boolean(client.initIndex);
15+
var originalDeleteIndex = client.deleteIndex
16+
? client.deleteIndex.bind(client)
17+
: undefined;
18+
19+
client.deleteIndex = function (deleteIndexName) {
20+
if (!originalDeleteIndex) {
1721
return client.initIndex(deleteIndexName).delete();
18-
};
22+
}
23+
if (!hasInitIndex) {
24+
return originalDeleteIndex({ indexName: deleteIndexName });
25+
}
26+
return originalDeleteIndex(deleteIndexName);
27+
};
1928
client.listIndexes = client.listIndexes || client.listIndices;
29+
client.initIndex =
30+
client.initIndex ||
31+
function (initIndexName) {
32+
return {
33+
addObjects: function (objects) {
34+
return client.saveObjects({
35+
objects: objects,
36+
indexName: initIndexName,
37+
});
38+
},
39+
clearObjects: function () {
40+
return client.clearObjects({ indexName: initIndexName });
41+
},
42+
setSettings: function (settings) {
43+
return client.setSettings({
44+
indexName: initIndexName,
45+
indexSettings: settings,
46+
});
47+
},
48+
waitTask: function (taskID) {
49+
return client.waitForTask({
50+
indexName,
51+
initIndexName,
52+
taskID: taskID,
53+
});
54+
},
55+
};
56+
};
57+
client.destroy = client.destroy || function () {};
2058

2159
var index = client.initIndex(indexName);
2260
index.addObjects =
@@ -32,6 +70,9 @@ function setup(indexName, fn) {
3270
};
3371
index.clearIndex = index.clearIndex || index.clearObjects;
3472

73+
// Ensure we go into the right integration branches (and client stays v5)
74+
client.initIndex = hasInitIndex ? client.initIndex : undefined;
75+
3576
return index
3677
.clearIndex()
3778
.then(function (content) {

packages/algoliasearch-helper/test/run.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,18 @@ jest.runCLI(dynamicJestConfig, projectsRootPaths).then(function (response) {
3838
process.env.INTEGRATION_TEST_APPID,
3939
process.env.INTEGRATION_TEST_API_KEY
4040
);
41-
client.deleteIndex =
42-
client.deleteIndex ||
43-
function (deleteIndexName) {
41+
var originalDeleteIndex = client.deleteIndex
42+
? client.deleteIndex.bind(client)
43+
: undefined;
44+
client.deleteIndex = function (deleteIndexName) {
45+
if (!originalDeleteIndex) {
4446
return client.initIndex(deleteIndexName).delete();
45-
};
47+
}
48+
if (!client.initIndex) {
49+
return originalDeleteIndex({ indexName: deleteIndexName });
50+
}
51+
return originalDeleteIndex(deleteIndexName);
52+
};
4653
client.listIndexes = client.listIndexes || client.listIndices;
4754

4855
client.listIndexes().then((content) => {

packages/algoliasearch-helper/test/spec/algoliasearch.helper/excludes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test('removeExclude should remove an exclusion', function (done) {
4040
try {
4141
helper.removeExclude(facetName, facetValueToExclude);
4242
} catch (e) {
43-
done.fail('Removing unset exclusions should be ok...');
43+
done(new Error('Removing unset exclusions should be ok...'));
4444
}
4545

4646
done();

packages/algoliasearch-helper/test/spec/algoliasearch.helper/queryID.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('the response handler should check that the query is not outdated', functio
3232
callCount++;
3333

3434
if (!shouldTriggerResult) {
35-
done.fail('The id was outdated');
35+
done(new Error('The id was outdated'));
3636
}
3737
});
3838

@@ -78,7 +78,7 @@ test('the error handler should check that the query is not outdated', function (
7878
callCount++;
7979

8080
if (!shouldTriggerError) {
81-
done.fail('The id was outdated');
81+
done(new Error('The id was outdated'));
8282
}
8383
});
8484

0 commit comments

Comments
 (0)