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

feat(tests): migrate for monorepo #38

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jobs:
- run: *run_yarn_install
- save_cache: *save_yarn_cache
- run:
name: Test specs
command: yarn test:saucelabs
name: Lint
command: yarn lint

workflows:
version: 2
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
},
overrides: [
{
files: ['specs/**/*.spec.ts'],
files: ['specs/**/*.spec.ts', 'all-flavors.spec.ts'],
extends: ['plugin:wdio/recommended'],
plugins: ['wdio'],
env: {
Expand Down
16 changes: 16 additions & 0 deletions all-flavors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { brandAndQuery } from './specs/brand-and-query.spec';
import { category } from './specs/category.spec';
import { initialStateFromRoute } from './specs/initial-state-from-route.spec';
import { pagination } from './specs/pagination.spec';
import { priceRange } from './specs/price-range.spec';
import { flavors } from './flavors';

flavors.forEach(flavor => {
describe(flavor, () => {
brandAndQuery(flavor);
category(flavor);
initialStateFromRoute(flavor);
pagination(flavor);
priceRange(flavor);
});
});
Comment on lines +1 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { brandAndQuery } from './specs/brand-and-query.spec';
import { category } from './specs/category.spec';
import { initialStateFromRoute } from './specs/initial-state-from-route.spec';
import { pagination } from './specs/pagination.spec';
import { priceRange } from './specs/price-range.spec';
import { flavors } from './flavors';
flavors.forEach(flavor => {
describe(flavor, () => {
brandAndQuery(flavor);
category(flavor);
initialStateFromRoute(flavor);
pagination(flavor);
priceRange(flavor);
});
});
import { createBrandAndQueryTestSuite } from './specs/brand-and-query.spec';
import { createCategoryTestSuite } from './specs/category.spec';
import { createInitialStateFromRouteTestSuite } from './specs/initial-state-from-route.spec';
import { createPaginationTestSuite } from './specs/pagination.spec';
import { createPriceRangeTestSuite } from './specs/price-range.spec';
import { flavors } from './flavors';
flavors.forEach(flavor => {
describe(flavor, () => {
createBrandAndQueryTestSuite(flavor);
createCategoryTestSuite(flavor);
createInitialStateFromRouteTestSuite(flavor);
createPaginationTestSuite(flavor);
createPriceRangeTestSuite(flavor);
});
});

3 changes: 3 additions & 0 deletions flavors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
flavors: ['js'],
};
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"scripts": {
"commit": "git-cz",
"version": "conventional-changelog --preset angular --infile CHANGELOG.md --same-file && git add CHANGELOG.md",
"test": "yarn test:local",
"test:local": "yarn link && cd tests && ./instantsearch.js.sh && ./react-instantsearch.sh && ./vue-instantsearch.sh",
"test:saucelabs": "SAUCELABS=1 yarn test:local",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "eslint --ext .js,.ts,.tsx --fix .",
"type-check": "tsc",
Expand Down
72 changes: 38 additions & 34 deletions specs/brand-and-query.spec.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
describe('InstantSearch - Search on specific brand and query filtering', () => {
it('navigates to the e-commerce demo', async () => {
await browser.url('examples/e-commerce/');
});
export function brandAndQuery(flavor: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function brandAndQuery(flavor: string) {
export function createBrandAndQueryTestSuite(flavor: string) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type should be typeof flavors[number], same for the other factories.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had that first but the flavor file needs to be cjs for it to work in the config, and then I'm either writing the flavours twice without validation, or have it as a string (what I preferred in the end)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah 😞 Can't we use .mjs configs with WebdriverIO?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with newer versions we can do it in typescript I think, I'll look if possible to upgrade once migrated in monorepo

const root = `examples/${flavor}/e-commerce/`;

it('selects "Apple" brand in list', async () => {
await browser.clickRefinementListItem('Apple');
});
describe('Search on specific brand and query filtering', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe('Search on specific brand and query filtering', () => {
describe('search on specific brand and query filtering', () => {

it('navigates to the e-commerce demo', async () => {
await browser.url(root);
});

it('fills search input with "macbook"', async () => {
await browser.setSearchBoxValue('macbook');
});
it('selects "Apple" brand in list', async () => {
await browser.clickRefinementListItem('Apple');
});

it('waits for the results list to be updated (wait for the "macbook" word to be highlighted)', async () => {
await browser.waitForElement('mark=MacBook');
});
it('fills search input with "macbook"', async () => {
await browser.setSearchBoxValue('macbook');
});

it('waits for the results list to be updated (wait for the "macbook" word to be highlighted)', async () => {
await browser.waitForElement('mark=MacBook');
});

it('must have the expected results', async () => {
const hitsTitles = await browser.getHitsTitles();
it('must have the expected results', async () => {
const hitsTitles = await browser.getHitsTitles();

expect(hitsTitles).toEqual([
'Apple - MacBook Air® (Latest Model) - 13.3" Display - Intel Core i5 - 8GB Memory - 128GB Flash Storage - Silver',
'Apple - MacBook Air® (Latest Model) - 13.3" Display - Intel Core i5 - 8GB Memory - 256GB Flash Storage - Silver',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M3 - 8GB Memory - 256GB Flash Storage - Space Gray',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M3 - 8GB Memory - 256GB Flash Storage - Gold',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M3 - 8GB Memory - 256GB Flash Storage - Rose Gold',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M3 - 8GB Memory - 256GB Flash Storage - Silver',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M5 - 8GB Memory - 512GB Flash Storage - Space Gray',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M5 - 8GB Memory - 512GB Flash Storage - Rose Gold',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M5 - 8GB Memory - 512GB Flash Storage - Gold',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M5 - 8GB Memory - 512GB Flash Storage - Silver',
'Apple - MacBook Pro with Retina display - 13.3" Display - 8GB Memory - 128GB Flash Storage - Silver',
'Apple - MacBook Pro® - 13" Display - Intel Core i5 - 8 GB Memory - 256GB Flash Storage (latest model) - Space Gray',
'Apple - MacBook® Pro - 15.4" Display - Intel Core i7 - 16GB Memory - 256GB Flash Storage - Silver',
'Apple - MacBook Pro® - 13" Display - Intel Core i5 - 8 GB Memory - 256GB Flash Storage (latest model) - Silver',
'Apple - MacBook® Pro - Intel Core i5 - 13.3" Display - 4GB Memory - 500GB Hard Drive - Silver',
'Apple - MacBook Pro 13.3" Refurbished Laptop - Intel Core i5 - 4GB Memory - 320GB - Silver',
]);
expect(hitsTitles).toEqual([
'Apple - MacBook Air® (Latest Model) - 13.3" Display - Intel Core i5 - 8GB Memory - 128GB Flash Storage - Silver',
'Apple - MacBook Air® (Latest Model) - 13.3" Display - Intel Core i5 - 8GB Memory - 256GB Flash Storage - Silver',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M3 - 8GB Memory - 256GB Flash Storage - Space Gray',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M3 - 8GB Memory - 256GB Flash Storage - Gold',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M3 - 8GB Memory - 256GB Flash Storage - Rose Gold',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M3 - 8GB Memory - 256GB Flash Storage - Silver',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M5 - 8GB Memory - 512GB Flash Storage - Space Gray',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M5 - 8GB Memory - 512GB Flash Storage - Rose Gold',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M5 - 8GB Memory - 512GB Flash Storage - Gold',
'Apple - Macbook® (Latest Model) - 12" Display - Intel Core M5 - 8GB Memory - 512GB Flash Storage - Silver',
'Apple - MacBook Pro with Retina display - 13.3" Display - 8GB Memory - 128GB Flash Storage - Silver',
'Apple - MacBook Pro® - 13" Display - Intel Core i5 - 8 GB Memory - 256GB Flash Storage (latest model) - Space Gray',
'Apple - MacBook® Pro - 15.4" Display - Intel Core i7 - 16GB Memory - 256GB Flash Storage - Silver',
'Apple - MacBook Pro® - 13" Display - Intel Core i5 - 8 GB Memory - 256GB Flash Storage (latest model) - Silver',
'Apple - MacBook® Pro - Intel Core i5 - 13.3" Display - 4GB Memory - 500GB Hard Drive - Silver',
'Apple - MacBook Pro 13.3" Refurbished Laptop - Intel Core i5 - 4GB Memory - 320GB - Silver',
]);
});
});
});
}
118 changes: 61 additions & 57 deletions specs/category.spec.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,67 @@
describe('InstantSearch - Search on specific category', () => {
it('navigates to the e-commerce demo', async () => {
await browser.url('examples/e-commerce/');
});
export function category(flavor: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function category(flavor: string) {
export function createCategoryTestSuite(flavor: string) {

const root = `examples/${flavor}/e-commerce/`;

it('selects "Appliances" category in list', async () => {
await browser.clickHierarchicalMenuItem('Appliances');
});
describe('Search on specific category', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe('Search on specific category', () => {
describe('search on specific category', () => {

it('navigates to the e-commerce demo', async () => {
await browser.url(root);
});

it('selects "Small Kitchen Appliances" category in list', async () => {
await browser.clickHierarchicalMenuItem('Small Kitchen Appliances');
});
it('selects "Appliances" category in list', async () => {
await browser.clickHierarchicalMenuItem('Appliances');
});

it('must have the expected results for "Small Kitchen Appliances"', async () => {
const hitsTitles = await browser.getHitsTitles();

expect(hitsTitles).toEqual([
'Insignia™ - 2.6 Cu. Ft. Compact Refrigerator - Black',
'Keurig - K50 Coffeemaker - Black',
'Keurig - K200 Brewer - Black',
'Frigidaire - 3.3 Cu. Ft. Compact Refrigerator - Stainless Steel',
'Ninja - Mega Kitchen System 72-Oz. Blender - Black',
'Ninja - Nutri Ninja Pro 24-Oz. Blender - Black/Silver',
'Oster - Inspire 2-Slice Wide-Slot Toaster - Black',
'Keurig - The Original Donut Shop K-Cup® Pods (18-Pack)',
'Chefman - Express Air Fryer - Black',
'Oster - 10-Speed Blender - Black',
'Keurig - Swiss Miss Milk Chocolate Hot Cocoa K-Cup® Pods (16-Pack)',
'Keurig - Cinnabon Classic Cinnamon Roll K-Cup® Pods (18-Pack) - Multi',
'Ninja - Nutri Ninja 32 Oz. Auto-iQ Blender - Black',
'Anova - Precision Cooker WiFi',
'Nespresso - VertuoLine Evoluo Espresso Maker/Coffeemaker - Gray',
'Magic Bullet - Blender - Silver/Black',
]);
});
it('selects "Small Kitchen Appliances" category in list', async () => {
await browser.clickHierarchicalMenuItem('Small Kitchen Appliances');
});

it('unselects "Small Kitchen Appliances" category in list', async () => {
await browser.clickHierarchicalMenuItem('Small Kitchen Appliances');
});
it('must have the expected results for "Small Kitchen Appliances"', async () => {
const hitsTitles = await browser.getHitsTitles();

expect(hitsTitles).toEqual([
'Insignia™ - 2.6 Cu. Ft. Compact Refrigerator - Black',
'Keurig - K50 Coffeemaker - Black',
'Keurig - K200 Brewer - Black',
'Frigidaire - 3.3 Cu. Ft. Compact Refrigerator - Stainless Steel',
'Ninja - Mega Kitchen System 72-Oz. Blender - Black',
'Ninja - Nutri Ninja Pro 24-Oz. Blender - Black/Silver',
'Oster - Inspire 2-Slice Wide-Slot Toaster - Black',
'Keurig - The Original Donut Shop K-Cup® Pods (18-Pack)',
'Chefman - Express Air Fryer - Black',
'Oster - 10-Speed Blender - Black',
'Keurig - Swiss Miss Milk Chocolate Hot Cocoa K-Cup® Pods (16-Pack)',
'Keurig - Cinnabon Classic Cinnamon Roll K-Cup® Pods (18-Pack) - Multi',
'Ninja - Nutri Ninja 32 Oz. Auto-iQ Blender - Black',
'Anova - Precision Cooker WiFi',
'Nespresso - VertuoLine Evoluo Espresso Maker/Coffeemaker - Gray',
'Magic Bullet - Blender - Silver/Black',
]);
});

it('unselects "Small Kitchen Appliances" category in list', async () => {
await browser.clickHierarchicalMenuItem('Small Kitchen Appliances');
});

it('must have the expected results for "Appliances"', async () => {
const hitsTitles = await browser.getHitsTitles();

it('must have the expected results for "Appliances"', async () => {
const hitsTitles = await browser.getHitsTitles();

expect(hitsTitles).toEqual([
'Nest - Learning Thermostat - 3rd Generation - Stainless Steel',
'LG - 1.1 Cu. Ft. Mid-Size Microwave - Stainless-Steel',
'Insignia™ - 2.6 Cu. Ft. Compact Refrigerator - Black',
'Keurig - K50 Coffeemaker - Black',
'iRobot - Roomba 650 Vacuuming Robot - Black',
'Shark - Navigator Lift-Away Deluxe Bagless Upright Vacuum - Blue',
'LG - 1.5 Cu. Ft. Mid-Size Microwave - Stainless Steel',
'Insignia™ - 5.0 Cu. Ft. Chest Freezer - White',
'Samsung - activewash 4.8 Cu. Ft. 11-Cycle High-Efficiency Top-Loading Washer - White',
'Samsung - 4.8 Cu. Ft. 11-Cycle High-Efficiency Top-Loading Washer - White',
'LG - 2.0 Cu. Ft. Full-Size Microwave - Stainless Steel',
'Shark - Rotator Professional Lift-Away HEPA Bagless 2-in-1 Upright Vacuum - Red',
'LG - 4.5 Cu. Ft. 8-Cycle High-Efficiency Top-Loading Washer - White',
'Samsung - 4.2 Cu. Ft. 9-Cycle High-Efficiency Steam Front-Loading Washer - Platinum',
'Panasonic - 1.3 Cu. Ft. Mid-Size Microwave - Stainless steel/black/silver',
'LG - 2.0 Cu. Ft. Mid-Size Microwave - Black Stainless',
]);
expect(hitsTitles).toEqual([
'Nest - Learning Thermostat - 3rd Generation - Stainless Steel',
'LG - 1.1 Cu. Ft. Mid-Size Microwave - Stainless-Steel',
'Insignia™ - 2.6 Cu. Ft. Compact Refrigerator - Black',
'Keurig - K50 Coffeemaker - Black',
'iRobot - Roomba 650 Vacuuming Robot - Black',
'Shark - Navigator Lift-Away Deluxe Bagless Upright Vacuum - Blue',
'LG - 1.5 Cu. Ft. Mid-Size Microwave - Stainless Steel',
'Insignia™ - 5.0 Cu. Ft. Chest Freezer - White',
'Samsung - activewash 4.8 Cu. Ft. 11-Cycle High-Efficiency Top-Loading Washer - White',
'Samsung - 4.8 Cu. Ft. 11-Cycle High-Efficiency Top-Loading Washer - White',
'LG - 2.0 Cu. Ft. Full-Size Microwave - Stainless Steel',
'Shark - Rotator Professional Lift-Away HEPA Bagless 2-in-1 Upright Vacuum - Red',
'LG - 4.5 Cu. Ft. 8-Cycle High-Efficiency Top-Loading Washer - White',
'Samsung - 4.2 Cu. Ft. 9-Cycle High-Efficiency Steam Front-Loading Washer - Platinum',
'Panasonic - 1.3 Cu. Ft. Mid-Size Microwave - Stainless steel/black/silver',
'LG - 2.0 Cu. Ft. Mid-Size Microwave - Black Stainless',
]);
});
});
});
}
Loading