Skip to content

Commit

Permalink
test(lyra): improves tests
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Aug 1, 2022
1 parent cb6a84b commit 94797aa
Show file tree
Hide file tree
Showing 6 changed files with 274,206 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ jest.config.js
*.dpack
*.css
get-imdb-dataset.mjs
**/tap-snapshots/**
**/dist/**
**/tap-snapshots/**
**/datasets/*.json
4 changes: 2 additions & 2 deletions packages/examples/with-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create, insert, search as lyraSearch } from '@nearform/lyra/dist/esm/lyra';
import { create, insert, search as lyraSearch } from '@nearform/lyra';
import { useEffect, useState } from 'react';

const db = create({
Expand Down Expand Up @@ -41,7 +41,7 @@ function App() {
const pokemons = result.hits.map((d) => pokemon?.find(p => p.id === (d as any).id));

if (pokemons.length && !pokemons.some((x) => !x)) {
setSearchPokemon([...new Set(pokemons)]);
setSearchPokemon(pokemons);
} else {
setSearchPokemon([]);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/lyra/src/lyra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type QueueDocParams<T extends PropertiesSchema> = {
config: InsertConfig;
};

type SearchResult<T extends PropertiesSchema> = {
export type SearchResult<T extends PropertiesSchema> = {
count: number;
hits: RetrievedDoc<T>[];
elapsed: bigint;
Expand Down
333 changes: 333 additions & 0 deletions packages/lyra/tap-snapshots/tests/lyra.dataset.test.ts.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`tests/lyra.dataset.test.ts TAP lyra.dataset should perform paginate search > should perform paginate search-page-1 1`] = `
Object {
"count": 2240,
"elapsed": 0n,
"hits": Array [
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-299",
"description": "The Samnites, seizing their chance when Rome is engaged on the Lombard plain, start the third Samnite War with a collection of mercenaries from Gaul, Sabine, and Etruscan allies to help them.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-298",
"description": "The Samnites defeat the Romans under Lucius Cornelius Scipio Barbatus in the Battle of Camerinum, first battle of the Third Samnite War.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-290",
"description": "Roman general and consul, Manius Curius Dentatus, gains a decisive victory over the Samnites, thereby ending a war that has lasted 50 years. He also reduces the Sabine insurgents to submission, their territory is annexed and they are granted civitas sine suffragio (ampquotcitizenship without the right to voteampquot). The Samnites are recognised by the Romans as autonomous allies. The Samnites are forced to give up some of their land to the Romans as compensation.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Greece",
},
"date": "-287",
"description": "Demetrius decides to leave Antigonus in charge of the war in Greece, assembles all his ships and embarks with his troops to attack Caria and Lydia, provinces in Asia Minor controlled by Lysimachus.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-282",
"description": "Rome declares war on Tarentum. King Pyrrhus of Epirus declares his willingness to come to the aid of Tarentum. Tarentum also looks for support from the Samnites and other Italian tribes in southern Italy.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Seleucid Empire",
},
"date": "-280",
"description": "Nicomedes, King of Bithynia, is threatened with an invasion from Antiochus who has already made war upon his father, Zipoites. Antiochus actually invades Bithynia but withdraws again without risking a battle.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Seleucid Empire",
},
"date": "-280",
"description": "Antiochus is defeated by Egypt's Ptolemy II in the Damascene War.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Seleucid Empire",
},
"date": "-272",
"description": "The Seleucid king Antiochus I Soter is defeated by Egypt's Ptolemy II during the First Syrian War. Ptolemy II annexes Miletus, Phoenicia and western Cilicia from Antiochus. As a result, Ptolemy II extends Egyptian rule as far as Caria and into most of Cilicia.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-264",
"description": "The tyrant of Syracuse, Hiero II, once more attacks the Mamertines. They ally themselves with a nearby Carthaginian fleet and hold off the Syracusans. However, when the Carthaginians do not leave, the Mamertines appeal to Rome for an alliance, hoping for more reliable protection. Although initially reluctant to assist lest it encourage other mercenary groups to mutiny, Rome is unwilling to see Carthaginian power spread further over Sicily and encroach on Italy. Rome therefore enters into an alliance with the Mamertines. By this action, the First Punic War begins and will embroil Rome in a conflict with Carthage that will continue for 23 years.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Greece",
},
"date": "-263",
"description": "The Athenians and Spartans, worn down by several years of war and the devastation of their lands, make peace with Antigonus II of Macedonia who thus retains his hold on Greece.",
"granularity": "year",
"id": "",
},
],
}
`

exports[`tests/lyra.dataset.test.ts TAP lyra.dataset should perform paginate search > should perform paginate search-page-2 1`] = `
Object {
"count": 2240,
"elapsed": 0n,
"hits": Array [
Object {
"categories": Object {
"first": "By place",
"second": "Greece",
},
"date": "-262",
"description": "After Athens surrenders following a long siege by Macedonian forces, Antigonus II Gonatas re-garrisons Athens and forbids the city from making war. Otherwise, he leaves Athens alone as the seat of philosophy and learning in Greece.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Seleucid Empire",
},
"date": "-259",
"description": "The Seleucid king Antiochus II starts the Second Syrian War against Ptolemy to avenge his father's losses. Antiochus II finds a willing ally in Antigonus II Gonatas, the king of Macedonia, who has been dealing with Ptolemy II's attempts to destabilize Macedonia.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-256",
"description": "Rome aims for a quick end to hostilities in the First Punic War and decides to invade the Carthaginian colonies in Northern Africa to force the enemy to accept terms. A major fleet is built, including transports for the army and its equipment, and warships for their protection. Carthage under Hamilcar tries to intervene but a force under the Roman general and consul Marcus Atilius Regulus and his colleague Lucius Manlius Vulso Longus defeat the Carthaginian fleet in the Battle of Cape Ecnomus off the southern coast of Sicily.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-256",
"description": "Following the Battle of Cape Ecnomus, the Romans land an army near Carthage and begin ravaging the Carthaginian countryside. The Roman army soon forces the capitulation of Clupea, a town 40 miles (64 kilometres) east of Carthage. After setting up Roman defenses for the city, the two consuls receive instructions from Rome that Vulso is to set sail for Rome, taking most of the fleet with him. Regulus, on the other hand, is to stay with the infantry and cavalry to finish the war.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Egypt",
},
"date": "-255",
"description": "In the Second Syrian War, Ptolemy II loses ground in Cilicia, Pamphylia, and Ionia, while Antiochus II regains Miletus and Ephesus. A peace is then concluded between Antiochus and Ptolemy under which Antiochus is to marry Ptolemy's daughter Berenice Syra.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Seleucid Empire",
},
"date": "-253",
"description": "The second Syrian War between the Seleucids and the Ptolemies ends. Antiochus II regains much of Anatolia from Ptolemy II, including the cities of Miletus and Ephesus, and also the Phoenician coast.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Seleucid Empire",
},
"date": "-253",
"description": "The war is concluded with the marriage of Antiochus to Ptolemy II's daughter, Berenice Syra. Antiochus divorces his previous wife, Laodice, and transfers the succession to Berenice's children.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-253",
"description": "A second Roman war fleet of 150 ships is wrecked on the voyage from Lilybaeum (in Sicily) to Rome.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Greece",
},
"date": "-253",
"description": "Macedonia's involvement in the second Syrian War ceases when Antigonus becomes preoccupied with the rebellion of Corinth and Chalcis, as well as an increase in enemy activity along Macedon's northern frontier.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-250",
"description": "In the Punic War, the Romans shift their attention to the southwest of Sicily. They send a naval expedition toward the Carthaginian city of Lilybaeum. En route, the Romans seize and burn the Carthaginian held cities of Selinous and Heraclea Minoa. The Romans then begin the siege of Lilybaeum.",
"granularity": "year",
"id": "",
},
],
}
`

exports[`tests/lyra.dataset.test.ts TAP lyra.dataset should perform paginate search > should perform paginate search-page-3 1`] = `
Object {
"count": 2240,
"elapsed": 0n,
"hits": Array [
Object {
"categories": Object {
"first": "By place",
"second": "Carthage",
},
"date": "-247",
"description": "By this stage in the Punic War, Carthage has lost to Rome all its Sicilian possessions except Lilybaeum (now Marsala) and Drepanum (now Trapani). Hamilcar Barca takes over the chief command of the Carthaginian forces in Sicily at a time when the island is almost completely in the hands of the Romans. Landing on the north-west of the island with a small mercenary force, he seizes a strong position on Mount Ercte (Monte Pellegrino, near Palermo), and not only successfully defends himself against all attacks, but also carries his raids as far as the coast of southern Italy.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Seleucid Empire",
},
"date": "-246",
"description": "Berenice's brother, Ptolemy III, sets about to avenge his sister's murder by invading Syria which begins the Third Syrian War (also known as the Laodicean War). Ptolemy III's navy, perhaps with the aid of rebels in the cities, advances against Seleucus II's forces as far as Thrace, across the Hellespont, and also captures some islands off the Anatolian coast.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Seleucid Empire",
},
"date": "-246",
"description": "Seleucus II Callinicus' mother, Laodice attempts to take control over the Seleucid Empire by insisting that Seleucus II make his younger brother, Antiochus Hierax, co-regent and give him all the Seleucid territory in Anatolia. Antiochus promptly declares independence and begins fighting a war with his brother.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-246",
"description": "In Rome, the number of praetors is increased from one to two. The second praetor is appointed to relieve the backlog of judicial business and to give the Republic a magistrate with Imperium who can field an army in an emergency when both consuls are away fighting a war.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Greece",
},
"date": "-244",
"description": "The war in Asia Minor and the Aegean Sea intensifies as the Achaean League allies itself to Ptolemy III of Egypt, while Seleucus II secures two allies in the Black Sea region. Ptolemy III's armies reach as far as Bactria and the borders of India in their attacks on the Seleucid Empire.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Roman Republic",
},
"date": "-241/03/10",
"description": " The Carthaginian fleet sent to relieve the Roman blockade of the Sicilian cities of Lilybaeum and Drepanum is totally defeated near the Aegates Islands off western Sicily by the Roman fleet led by Roman consul and commander, Gaius Lutatius Catulus. The result is a decisive Roman victory which forces an end to the protracted First Punic War, to Rome's distinct advantage.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Greece",
},
"date": "-241",
"description": "The Eurypontid King of Sparta, Agis IV, is called away from Sparta when Aratus of Sicyon, temporarily Sparta's ally, requests Agis' aid in his war against the Aetolians. Upon his return, Agis finds that his supporters are discontented with the rule of his uncle, Agesilaus, and are disillusioned by the delay in implementing the Agis IV's reforms. As a result, the Agiad king of Sparta, Leonidas II, gains power, supported by mercenaries. Rather than engage in a war with Leonidas, Agis takes sanctuary in a temple, but is enticed out, summarily tried and then executed, along with his mother and grandmother.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Carthage",
},
"date": "-240",
"description": "Two of Carthage's mercenary commanders ampampndash Spendius and Mathos ampampndash convince the Libyan conscripts in the mercenary army, that is currently occupying the Carthaginian city of Tunis, to accept their leadership. They persuade the native Libyans that Carthage will take revenge against them for their part in the conflict once the foreign mercenaries are paid and sent home. They then convince the combined mercenary armies to revolt against Carthage and convince the various native Libyan towns and cities to back the revolt. Spendius and Mathos then take the Carthaginian commander Gesco as a hostage. What has started as an argument over pay owed to soldiers by the Carthaginian Government, explodes into a full-scale revolution, known as the Mercenary War.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Carthage",
},
"date": "-239",
"description": "Concerned that Hamilcar Barca's leniency in pardoning those who he has captured who have participated in the Mercenary War will encourage others to defect, Mathos and Spendius order the mutilation and execution of ampquotabout seven hundredampquot Carthaginian prisoners, including Gesco. With the mercenaries jointly guilty of these atrocities, defectors dare not face Carthaginian justice under Hamilcar.",
"granularity": "year",
"id": "",
},
Object {
"categories": Object {
"first": "By place",
"second": "Carthage",
},
"date": "-238",
"description": "The Carthaginian armies besiege and capture Utica and Hippacritae. This ends the Carthaginian civil war.",
"granularity": "year",
"id": "",
},
],
}
`
Loading

0 comments on commit 94797aa

Please sign in to comment.