Skip to content

Commit

Permalink
style: Fix tests style
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbrea committed Jun 4, 2023
1 parent 0d796fb commit db3d743
Show file tree
Hide file tree
Showing 142 changed files with 1,719 additions and 64 deletions.
15 changes: 14 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,25 @@ module.exports = {
fetch: false,
},
plugins: ["jest", "no-only-tests", "jest-formatting"],
extends: ["plugin:jest/recommended"],
extends: [
"eslint:recommended",
"prettier",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:jest/recommended",
"plugin:jest-formatting/strict",
],
rules: {
"jest/no-conditional-expect": [0],
"no-only-tests/no-only-tests": [2],
"jest/no-done-callback": [0],
},
settings: {
"import/resolver": {
typescript: true,
node: true,
},
},
},
{
files: ["test/*/cypress/**/*.js"],
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/affected-projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
main-branch-name: ${{github.event.pull_request.base.ref}}
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: 6.15.1
- name: Use Node.js
Expand All @@ -25,7 +25,7 @@ jobs:
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
Expand All @@ -37,7 +37,7 @@ jobs:
run: pnpm install
- name: Affected report
id: affected-report
run: echo "::set-output name=report::$(./scripts/commands/affected-report.sh origin/${{github.event.pull_request.base.ref}})"
run: echo "report=$(./scripts/commands/affected-report.sh origin/${{github.event.pull_request.base.ref}})" >> $GITHUB_OUTPUT
- name: Comment affected
uses: unsplash/comment-on-pr@v1.3.0
env:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
main-branch-name: ${{github.event.pull_request.base.ref}}
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: "6.x"
- name: Use Node.js
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: "6.x"
- name: Use Node.js
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
path: "workspace.json"
prop_path: "projects.${{matrix.projectName}}"
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: "6.x"
- name: Use Node.js
Expand Down Expand Up @@ -221,7 +221,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: "6.x"
- name: Use Node.js
Expand Down Expand Up @@ -261,7 +261,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: "6.x"
- name: Use Node.js
Expand Down Expand Up @@ -298,7 +298,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: "6.x"
- name: Use Node.js
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check-affected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
main-branch-name: ${{github.event.pull_request.base.ref}}
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: 6.15.1
- name: Use Node.js
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
Expand All @@ -40,7 +40,7 @@ jobs:
run: pnpm install
- name: Check affected report
id: check-affected-report
run: echo "::set-output name=report::$(./scripts/commands/affected-check-report.sh origin/${{github.event.pull_request.base.ref}})"
run: echo "report=$(./scripts/commands/affected-check-report.sh origin/${{github.event.pull_request.base.ref}})" >> $GITHUB_OUTPUT
- name: Comment check affected
uses: unsplash/comment-on-pr@v1.3.0
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: "6.x"
- uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2.2.2
uses: pnpm/action-setup@v2.2.4
with:
version: "6.x"
- uses: actions/setup-node@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe("configClient method", () => {
const HOST = "foo-host";

let sandbox;

beforeAll(() => {
sandbox = sinon.createSandbox();
sandbox.spy(providers.getByTag(TAG), "config");
Expand All @@ -24,6 +25,7 @@ describe("configClient method", () => {
host: HOST,
port: PORT,
});

expect(providers.getByTag(TAG).config.getCall(0).args[0].baseUrl).toEqual(
`http://${HOST}:${PORT}${BASE_PATH}`
);
Expand Down
24 changes: 24 additions & 0 deletions packages/admin-api-client/test/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("AdminApiClient class", () => {
describe("when reading about", () => {
it("should return current version", async () => {
const about = await apiClient.readAbout();

expect(about.versions.adminApi).toBeDefined();
});
});
Expand All @@ -44,25 +45,29 @@ describe("AdminApiClient class", () => {
});
await wait(3000);
const alerts = await apiClient.readAlerts();

expect(alerts.length).toEqual(0);
});
});

describe("when there are alerts about files with error", () => {
it("should return 2 alerts", async () => {
expect.assertions(1);

await apiClient.updateConfig({
files: { path: "mocks-with-error" },
});
await wait(3000);
const alerts = await apiClient.readAlerts();

expect(alerts.length).toEqual(2);
});

it("alert about empty collections should exist", async () => {
const alerts = await apiClient.readAlerts();
const alertId = alerts[0].id;
const alert = await apiClient.readAlert(alertId);

expect(alert.id).toEqual(alertId);
expect(alert.message).toEqual(expect.stringContaining("No collections found"));
});
Expand All @@ -71,6 +76,7 @@ describe("AdminApiClient class", () => {
const alerts = await apiClient.readAlerts();
const alertId = alerts[1].id;
const alert = await apiClient.readAlert(alertId);

expect(alert.id).toEqual(alertId);
expect(alert.message).toEqual(expect.stringContaining("Error loading file"));
expect(alert.message).toEqual(expect.stringContaining("collections.js"));
Expand All @@ -89,6 +95,7 @@ describe("AdminApiClient class", () => {
});
await wait(2000);
const alerts = await apiClient.readAlerts();

expect(alerts.length).toEqual(0);
});
});
Expand All @@ -104,13 +111,15 @@ describe("AdminApiClient class", () => {
},
});
const settings = await apiClient.readConfig();

expect(settings.mock.routes.delay).toEqual(2000);
});
});

describe("when reading collections", () => {
it("should return collections", async () => {
const collections = await apiClient.readCollections();

expect(collections).toEqual([
{
id: "base",
Expand All @@ -131,6 +140,7 @@ describe("AdminApiClient class", () => {
describe("when reading collection", () => {
it("should return collection data", async () => {
const collection = await apiClient.readCollection("base");

expect(collection).toEqual({
id: "base",
from: null,
Expand All @@ -143,6 +153,7 @@ describe("AdminApiClient class", () => {
describe("when reading routes", () => {
it("should return routes", async () => {
const data = await apiClient.readRoutes();

expect(data).toEqual([
{
id: "get-user",
Expand All @@ -158,6 +169,7 @@ describe("AdminApiClient class", () => {
describe("when reading route", () => {
it("should return route data", async () => {
const data = await apiClient.readRoute("get-user");

expect(data).toEqual({
id: "get-user",
delay: null,
Expand All @@ -171,6 +183,7 @@ describe("AdminApiClient class", () => {
describe("when reading variants", () => {
it("should return route variants", async () => {
const data = await apiClient.readVariants();

expect(data).toEqual([
{
id: "get-user:1",
Expand All @@ -195,6 +208,7 @@ describe("AdminApiClient class", () => {
describe("when reading variant", () => {
it("should return variant data", async () => {
const data = await apiClient.readVariant("get-user:2");

expect(data).toEqual({
id: "get-user:2",
route: "get-user",
Expand All @@ -209,17 +223,20 @@ describe("AdminApiClient class", () => {
describe("custom route variants", () => {
it("should be empty", async () => {
const data = await apiClient.readCustomRouteVariants();

expect(data).toEqual([]);
});

it("should be able to add one", async () => {
await apiClient.useRouteVariant("get-user:2");
const data = await apiClient.readCustomRouteVariants();

expect(data).toEqual([{ id: "get-user:2" }]);
});

it("should reject if route variant don't exist", async () => {
expect.assertions(1);

await apiClient.useRouteVariant("foo").catch((err) => {
expect(err.message).toEqual('Route variant with id "foo" was not found');
});
Expand All @@ -228,6 +245,7 @@ describe("AdminApiClient class", () => {
it("should be empty after restoring them to the collection defaults", async () => {
await apiClient.restoreRouteVariants();
const data = await apiClient.readCustomRouteVariants();

expect(data).toEqual([]);
});
});
Expand All @@ -246,12 +264,14 @@ describe("AdminApiClient class", () => {
port: 3120,
});
const settings = await apiClient.readConfig();

expect(settings.plugins.adminApi.port).toEqual(3120);
});

it("should do nothing if not port is provided", async () => {
apiClient.configClient();
const settings = await apiClient.readConfig();

expect(settings.plugins.adminApi.port).toEqual(3120);
});

Expand All @@ -268,6 +288,7 @@ describe("AdminApiClient class", () => {
port: 3110,
});
const settings = await apiClient.readConfig();

expect(settings.plugins.adminApi.port).toEqual(3110);
});
});
Expand Down Expand Up @@ -303,12 +324,14 @@ describe("AdminApiClient class", () => {
agent: httpsAgent,
});
const settings = await apiClient.readConfig();

expect(settings.plugins.adminApi.port).toEqual(3120);
});

it("should do nothing if no protocol is provided", async () => {
apiClient.configClient();
const settings = await apiClient.readConfig();

expect(settings.plugins.adminApi.port).toEqual(3120);
});

Expand All @@ -330,6 +353,7 @@ describe("AdminApiClient class", () => {
agent: null,
});
const settings = await apiClient.readConfig();

expect(settings.plugins.adminApi.port).toEqual(3110);
});
});
Expand Down
Loading

0 comments on commit db3d743

Please sign in to comment.