Skip to content

Commit

Permalink
refactor(tests): move to jest (#411)
Browse files Browse the repository at this point in the history
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
  • Loading branch information
wolfy1339 and gr2m committed Jun 11, 2021
1 parent 39584d9 commit 4e22625
Show file tree
Hide file tree
Showing 31 changed files with 6,637 additions and 6,163 deletions.
12,424 changes: 6,492 additions & 5,932 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"pretest": "npm run -s lint",
"lint": "prettier --check '{lib,scenarios,test}/**/*.{js,json}' index.js README.md package.json",
"lint:fix": "prettier --write '{lib,scenarios,test}/**/*.{js,json}' index.js README.md package.json",
"test": "tap --100 --coverage 'test/**/*-test.js' 'scenarios/**/test.js'",
"test:unit": "tap 'test/unit/**/*-test.js'",
"test:integration": "tap 'test/integration/**/*-test.js'",
"test:scenarios": "tap 'scenarios/**/test.js'",
"test": "jest --coverage 'scenarios/.*/test.js' 'test/.*/.*.test.js'",
"test:unit": "jest -i 'test/unit/.*/*.test.js'",
"test:integration": "jest -i 'test/integration/.*/*.test.js'",
"test:scenarios": "jest -i 'scenarios/.*/test.js'",
"semantic-release": "semantic-release"
},
"repository": "github:octokit/fixtures",
Expand All @@ -35,6 +35,7 @@
"url-template": "^2.0.8"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"axios": "^0.21.0",
"axios-debug-log": "^0.8.0",
"bottleneck": "^2.12.0",
Expand All @@ -45,19 +46,23 @@
"gunzip-maybe": "^1.4.1",
"humanize-string": "^2.0.0",
"into-stream": "^6.0.0",
"jest": "^27.0.4",
"minimist": "^1.2.5",
"mkdirp": "^1.0.3",
"prettier": "2.3.1",
"proxyquire": "^2.1.0",
"semantic-release": "^17.0.0",
"tap": "^15.0.0",
"tar-stream": "^2.0.1"
},
"nyc": {
"exclude": [
"test",
"scenarios/**/test.js"
]
"jest": {
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
},
"renovate": {
"extends": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Get repository", async (t) => {
test("Get repository", async () => {
const mock = fixtures.mock(
"api.github.com/add-and-remove-repository-collaborator"
);
Expand All @@ -29,7 +28,7 @@ test("Get repository", async (t) => {
},
}).catch(mock.explain);

t.is(invitationsResponse.data[0].id, 1000);
expect(invitationsResponse.data[0].id).toBe(1000);

// https://developer.github.com/v3/repos/invitations/#accept-a-repository-invitation
await axios({
Expand Down Expand Up @@ -72,6 +71,5 @@ test("Get repository", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
6 changes: 2 additions & 4 deletions scenarios/api.github.com/add-labels-to-issue/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Get repository", async (t) => {
test("Get repository", async () => {
const mock = fixtures.mock("api.github.com/add-labels-to-issue");

// https://developer.github.com/v3/issues/#create-an-issue
Expand Down Expand Up @@ -34,6 +33,5 @@ test("Get repository", async (t) => {
},
}); // .catch(mock.explain)

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
6 changes: 2 additions & 4 deletions scenarios/api.github.com/branch-protection/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Branch protection", async (t) => {
test("Branch protection", async () => {
const mock = fixtures.mock("api.github.com/branch-protection");

// https://developer.github.com/v3/repos/branches/#get-branch-protection
Expand Down Expand Up @@ -85,6 +84,5 @@ test("Branch protection", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
8 changes: 3 additions & 5 deletions scenarios/api.github.com/create-file/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Create File", async (t) => {
test("Create File", async () => {
const mock = fixtures.mock("api.github.com/create-file");

const result = await axios({
Expand All @@ -20,7 +19,6 @@ test("Create File", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.is(result.data.content.type, "file");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
expect(result.data.content.type).toBe("file");
});
8 changes: 3 additions & 5 deletions scenarios/api.github.com/create-status/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Create status", async (t) => {
test("Create status", async () => {
const mock = fixtures.mock("api.github.com/create-status");

// create failure status
Expand Down Expand Up @@ -60,7 +59,6 @@ test("Create status", async (t) => {
},
});

t.is(data.state, "failure", "combined state is failure");
t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(data.state).toBe("failure");
expect(mock.done.bind(mock)).not.toThrow();
});
11 changes: 4 additions & 7 deletions scenarios/api.github.com/errors/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Errors", async (t) => {
t.plan(2);
test("Errors", async () => {
expect.assertions(2);
const mock = fixtures.mock("api.github.com/errors");

try {
Expand All @@ -22,10 +21,8 @@ test("Errors", async (t) => {
},
});
} catch (error) {
t.is(error.response.status, 422);
expect(error.response.status).toBe(422);
}

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");

t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
13 changes: 5 additions & 8 deletions scenarios/api.github.com/get-archive/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Get archive", async (t) => {
test("Get archive", async () => {
const mock = fixtures.mock("api.github.com/get-archive");

// https://developer.github.com/v3/repos/#edit
Expand All @@ -19,7 +18,7 @@ test("Get archive", async (t) => {
maxRedirects: 0,
})
.catch((error) => {
t.is(error.response.status, 302);
expect(error.response.status).toBe(302);
if (error.response.status === 302) {
return error.response.headers.location;
}
Expand All @@ -28,8 +27,7 @@ test("Get archive", async (t) => {
})
.catch(mock.explain);

t.is(
redirectLocation,
expect(redirectLocation).toBe(
"https://codeload.github.com/octokit-fixture-org/get-archive/legacy.tar.gz/refs/heads/main"
);

Expand All @@ -42,8 +40,7 @@ test("Get archive", async (t) => {
},
});

t.is(Buffer.from(result.data, "binary").toString("hex").length, 340);
expect(Buffer.from(result.data, "binary").toString("hex").length).toBe(340);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
15 changes: 6 additions & 9 deletions scenarios/api.github.com/get-content/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Get repository", async (t) => {
test("Get repository", async () => {
const mock = fixtures.mock("api.github.com/get-content");

const jsonResult = await axios({
Expand All @@ -15,8 +14,8 @@ test("Get repository", async (t) => {
},
}).catch(mock.explain);

t.is(jsonResult.data.length, 1);
t.is(jsonResult.data[0].path, "README.md");
expect(jsonResult.data.length).toBe(1);
expect(jsonResult.data[0].path).toBe("README.md");

const rawResult = await axios({
method: "get",
Expand All @@ -27,12 +26,10 @@ test("Get repository", async (t) => {
},
}).catch(mock.explain);

t.is(rawResult.data, "# hello-world");
t.is(
rawResult.headers["content-type"],
expect(rawResult.data).toBe("# hello-world");
expect(rawResult.headers["content-type"]).toBe(
"application/vnd.github.v3.raw; charset=utf-8"
);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
8 changes: 3 additions & 5 deletions scenarios/api.github.com/get-organization/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Get organization", async (t) => {
test("Get organization", async () => {
const mock = fixtures.mock("api.github.com/get-organization");

const result = await axios({
Expand All @@ -15,7 +14,6 @@ test("Get organization", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.is(result.data.id, 1000);
t.end();
expect(mock.done.bind(mock)).not.toThrow();
expect(result.data.id).toBe(1000);
});
8 changes: 3 additions & 5 deletions scenarios/api.github.com/get-repository/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Get repository", async (t) => {
test("Get repository", async () => {
const mock = fixtures.mock("api.github.com/get-repository");

const result = await axios({
Expand All @@ -15,7 +14,6 @@ test("Get repository", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.is(result.data.id, 1000);
t.end();
expect(mock.done.bind(mock)).not.toThrow();
expect(result.data.id).toBe(1000);
});
6 changes: 2 additions & 4 deletions scenarios/api.github.com/get-root/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Get repository", async (t) => {
test("Get repository", async () => {
const mock = fixtures.mock("api.github.com/get-root");

await axios({
Expand All @@ -15,6 +14,5 @@ test("Get repository", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
6 changes: 2 additions & 4 deletions scenarios/api.github.com/git-refs/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Git references", async (t) => {
test("Git references", async () => {
const mock = fixtures.mock("api.github.com/git-refs");

// https://developer.github.com/v3/git/refs/#get-all-references
Expand Down Expand Up @@ -70,6 +69,5 @@ test("Git references", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
6 changes: 2 additions & 4 deletions scenarios/api.github.com/labels/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Labels", async (t) => {
test("Labels", async () => {
const mock = fixtures.mock("api.github.com/labels");

// https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository
Expand Down Expand Up @@ -71,6 +70,5 @@ test("Labels", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});
6 changes: 2 additions & 4 deletions scenarios/api.github.com/lock-issue/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const axios = require("axios");
const { test } = require("tap");

const fixtures = require("../../..");

test("Lock issues", async (t) => {
test("Lock issues", async () => {
const mock = fixtures.mock("api.github.com/lock-issue");

// https://developer.github.com/v3/issues/#lock-an-issue
Expand All @@ -30,6 +29,5 @@ test("Lock issues", async (t) => {
},
}).catch(mock.explain);

t.doesNotThrow(mock.done.bind(mock), "satisfies all mocks");
t.end();
expect(mock.done.bind(mock)).not.toThrow();
});

0 comments on commit 4e22625

Please sign in to comment.