Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit 64963bc

Browse files
committed
test(e2e): migrate to jest
1 parent 5daa86a commit 64963bc

File tree

9 files changed

+339
-809
lines changed

9 files changed

+339
-809
lines changed

.eslintrc

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,16 @@
1010
},
1111
"overrides": [
1212
{
13-
"files": ["./src/**/*.test.ts", "./tests/**/*.js"],
14-
"plugins": ["jest"],
15-
"env": {
16-
"jest/globals": true
17-
}
18-
},
19-
{
20-
"files": ["./e2e/**/*.js"],
21-
"env": {
22-
"mocha": true
23-
},
13+
"files": ["./scripts/**/*.js", "./tests/**/*.js"],
2414
"rules": {
25-
"import/no-unresolved": "off"
15+
"import/no-extraneous-dependencies": "off"
2616
}
2717
},
2818
{
29-
"files": ["./e2e/**/*.js", "./scripts/**/*.js", "./tests/**/*.js"],
30-
"rules": {
31-
"import/no-extraneous-dependencies": "off"
19+
"files": ["./e2e/**/*.js", "./src/**/*.test.ts", "./tests/**/*.js"],
20+
"plugins": ["jest"],
21+
"env": {
22+
"jest/globals": true
3223
}
3324
}
3425
]

e2e/delete.spec.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
1-
const assert = require('assert')
2-
1+
// eslint-disable-next-line import/no-unresolved
32
const { create } = require('..')
4-
const handleError = require('./helpers/handleError')
53

64
const postgrestClient = create({
75
axiosConfig: { baseURL: 'http://localhost:3000' },
86
})
97

108
describe('E2E: #delete()', () => {
11-
it(`should return undefined with a single item and no option`, async () => {
12-
try {
13-
await postgrestClient.post('/customers', {
14-
email: 'bob.marley@protonmail.com',
15-
name: 'Bob Marley',
16-
})
17-
const result = await postgrestClient.eq('email', 'bob.marley@protonmail.com').delete('/customers')
9+
beforeEach(async () => {
10+
await postgrestClient.delete('/customers')
11+
})
12+
13+
test(`should return undefined with a single item and no option`, async () => {
14+
await postgrestClient.post('/customers', {
15+
email: 'bob.marley@protonmail.com',
16+
name: 'Bob Marley',
17+
})
18+
const result = await postgrestClient.eq('email', 'bob.marley@protonmail.com').delete('/customers')
1819

19-
assert.equal(result.data, undefined)
20-
} catch (err) {
21-
handleError(err)
22-
}
20+
expect(result.data).toBeUndefined()
2321
})
2422

25-
it(`should return undefined with a single item and no option`, async () => {
26-
try {
27-
await postgrestClient.post('/customers', {
28-
email: 'bob.marley@protonmail.com',
29-
name: 'Bob Marley',
30-
})
31-
const result = await postgrestClient.eq('email', 'bob.marley@protonmail.com').delete('/customers', {
32-
return: 'representation',
33-
})
23+
test(`should return undefined with a single item and { return: "representation" }`, async () => {
24+
await postgrestClient.post('/customers', {
25+
email: 'bob.marley@protonmail.com',
26+
name: 'Bob Marley',
27+
})
28+
const result = await postgrestClient.eq('email', 'bob.marley@protonmail.com').delete('/customers', {
29+
return: 'representation',
30+
})
3431

35-
assert.equal(result.data.email, 'bob.marley@protonmail.com')
36-
assert.equal(result.data.name, 'Bob Marley')
37-
} catch (err) {
38-
handleError(err)
39-
}
32+
expect(result.data.email).toEqual('bob.marley@protonmail.com')
33+
expect(result.data.name).toEqual('Bob Marley')
4034
})
4135
})

e2e/helpers/handleError.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

e2e/ilike.spec.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
const assert = require('assert')
2-
1+
// eslint-disable-next-line import/no-unresolved
32
const { create } = require('..')
43

54
const postgrestClient = create({
65
axiosConfig: { baseURL: 'http://localhost:3000' },
76
})
87

98
describe('E2E: #ilike()', () => {
10-
it(`should find all the books which title contains "an" or "An"`, async () => {
9+
test(`should find all the books which title contains "an" or "An"`, async () => {
1110
const { data: result } = await postgrestClient
1211
.select('title')
1312
.select('authors(name)')
1413
.ilike('title', 'an')
1514
.orderBy('title')
1615
.get('/books')
1716

18-
assert.equal(result.length, 3)
19-
assert.equal(result[0].title, "An Analysis of Betty Friedan's The Feminine Mystique")
20-
assert.equal(result[0].authors.name, 'Elizabeth Whitaker')
21-
assert.equal(result[1].title, 'Anna Karenina')
22-
assert.equal(result[1].authors.name, 'Leo Tolstoy')
23-
assert.equal(result[2].title, 'War and Peace')
24-
assert.equal(result[2].authors.name, 'Leo Tolstoy')
17+
expect(result.length).toEqual(3)
18+
expect(result[0].title).toEqual("An Analysis of Betty Friedan's The Feminine Mystique")
19+
expect(result[0].authors.name).toEqual('Elizabeth Whitaker')
20+
expect(result[1].title).toEqual('Anna Karenina')
21+
expect(result[1].authors.name).toEqual('Leo Tolstoy')
22+
expect(result[2].title).toEqual('War and Peace')
23+
expect(result[2].authors.name).toEqual('Leo Tolstoy')
2524
})
2625
})

e2e/like.spec.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
1-
const assert = require('assert')
2-
1+
// eslint-disable-next-line import/no-unresolved
32
const { create } = require('..')
43

54
const postgrestClient = create({
65
axiosConfig: { baseURL: 'http://localhost:3000' },
76
})
87

98
describe('E2E: #like()', () => {
10-
it(`should find all the books which title contains "u"`, async () => {
9+
test(`should find all the books which title contains "u"`, async () => {
1110
const { data: result } = await postgrestClient
1211
.select('title')
1312
.select('authors(name)')
1413
.like('title', 'u')
1514
.orderBy('title')
1615
.get('/books')
1716

18-
assert.equal(result.length, 2)
19-
assert.equal(result[0].title, "An Analysis of Betty Friedan's The Feminine Mystique")
20-
assert.equal(result[0].authors.name, 'Elizabeth Whitaker')
21-
assert.equal(result[1].title, 'Crow Blue')
22-
assert.equal(result[1].authors.name, 'Adriana Lisboa')
17+
expect(result.length).toEqual(2)
18+
expect(result[0].title).toEqual("An Analysis of Betty Friedan's The Feminine Mystique")
19+
expect(result[0].authors.name).toEqual('Elizabeth Whitaker')
20+
expect(result[1].title).toEqual('Crow Blue')
21+
expect(result[1].authors.name).toEqual('Adriana Lisboa')
2322
})
2423

25-
it(`should find all the books which title contains "U"`, async () => {
24+
test(`should find all the books which title contains "U"`, async () => {
2625
const { data: result } = await postgrestClient
2726
.select('title')
2827
.select('authors(name)')
2928
.like('title', 'U')
3029
.orderBy('title')
3130
.get('/books')
3231

33-
assert.equal(result.length, 1)
34-
assert.equal(result[0].title, 'The Unbearable Lightness of Being')
35-
assert.equal(result[0].authors.name, 'Milan Kundera')
32+
expect(result.length).toEqual(1)
33+
expect(result[0].title).toEqual('The Unbearable Lightness of Being')
34+
expect(result[0].authors.name).toEqual('Milan Kundera')
3635
})
3736
})

e2e/post.spec.js

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,62 @@
1-
const assert = require('assert')
2-
1+
// eslint-disable-next-line import/no-unresolved
32
const { create } = require('..')
4-
const handleError = require('./helpers/handleError')
53

64
const postgrestClient = create({
75
axiosConfig: { baseURL: 'http://localhost:3000' },
86
})
97

108
describe('E2E: #post()', () => {
119
beforeEach(async () => {
12-
await postgrestClient.gt('id', 1).delete('/customers')
10+
await postgrestClient.delete('/customers')
11+
})
12+
13+
test(`should return undefined with a single item and no option`, async () => {
14+
const result = await postgrestClient.post('/customers', {
15+
email: 'bob.marley@protonmail.com',
16+
name: 'Bob Marley',
17+
})
18+
19+
expect(result.data).toBeUndefined()
1320
})
1421

15-
it(`should return undefined with a single item and no option`, async () => {
16-
try {
17-
const result = await postgrestClient.post('/customers', {
22+
test(`should return the created row with a single item and { return: "representation" }`, async () => {
23+
const result = await postgrestClient.post(
24+
'/customers',
25+
{
1826
email: 'bob.marley@protonmail.com',
1927
name: 'Bob Marley',
20-
})
21-
22-
assert.equal(result.data, undefined)
23-
} catch (err) {
24-
handleError(err)
25-
}
28+
},
29+
{
30+
return: 'representation',
31+
},
32+
)
33+
34+
expect(result.data.email).toEqual('bob.marley@protonmail.com')
35+
expect(result.data.name).toEqual('Bob Marley')
2636
})
2737

28-
it(`should return the created row with a single item and { return: "representation" }`, async () => {
29-
try {
30-
const result = await postgrestClient.post(
31-
'/customers',
38+
test(`should return the created rows with multiple items and { return: "representation" }`, async () => {
39+
const result = await postgrestClient.post(
40+
'/customers',
41+
[
3242
{
3343
email: 'bob.marley@protonmail.com',
3444
name: 'Bob Marley',
3545
},
3646
{
37-
return: 'representation',
47+
email: 'bob.sinclar@protonmail.com',
48+
name: 'Bob Sinclar',
3849
},
39-
)
40-
41-
assert.equal(result.data.email, 'bob.marley@protonmail.com')
42-
assert.equal(result.data.name, 'Bob Marley')
43-
} catch (err) {
44-
handleError(err)
45-
}
46-
})
47-
48-
it(`should return the created rows with multiple items and { return: "representation" }`, async () => {
49-
try {
50-
const result = await postgrestClient.post(
51-
'/customers',
52-
[
53-
{
54-
email: 'bob.marley@protonmail.com',
55-
name: 'Bob Marley',
56-
},
57-
{
58-
email: 'bob.sinclar@protonmail.com',
59-
name: 'Bob Sinclar',
60-
},
61-
],
62-
{
63-
return: 'representation',
64-
},
65-
)
66-
67-
assert.equal(result.data.length, 2)
68-
assert.equal(result.data[0].email, 'bob.marley@protonmail.com')
69-
assert.equal(result.data[0].name, 'Bob Marley')
70-
assert.equal(result.data[1].email, 'bob.sinclar@protonmail.com')
71-
assert.equal(result.data[1].name, 'Bob Sinclar')
72-
} catch (err) {
73-
handleError(err)
74-
}
50+
],
51+
{
52+
return: 'representation',
53+
},
54+
)
55+
56+
expect(result.data.length).toEqual(2)
57+
expect(result.data[0].email).toEqual('bob.marley@protonmail.com')
58+
expect(result.data[0].name).toEqual('Bob Marley')
59+
expect(result.data[1].email).toEqual('bob.sinclar@protonmail.com')
60+
expect(result.data[1].name).toEqual('Bob Sinclar')
7561
})
7662
})

jest.e2e.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
bail: true,
3+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
4+
roots: ['<rootDir>/e2e'],
5+
verbose: true,
6+
}

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"prepare": "husky install",
1414
"setup": "node ./scripts/dev/setup.js",
1515
"test": "yarn test:lint && yarn test:unit",
16-
"test:e2e": "yarn build && mocha -b ./e2e/*.spec.js",
16+
"test:e2e": "yarn build && jest -c ./jest.e2e.config.js --runInBand",
1717
"test:e2e:v8": "cross-env POSTGREST_VERSION=v8.0.0.20211102 yarn setup && yarn test:e2e",
1818
"test:e2e:v9": "yarn setup && yarn test:e2e",
1919
"test:lint": "eslint .",
@@ -38,16 +38,12 @@
3838
"husky": "7.0.4",
3939
"jest": "27.4.7",
4040
"knex": "1.0.1",
41-
"mocha": "9.1.4",
4241
"pg": "8.7.1",
4342
"rollup": "2.66.0",
4443
"shelljs": "0.8.5",
4544
"ts-jest": "27.1.3",
4645
"typescript": "4.5.5"
4746
},
48-
"resolutions": {
49-
"nanoid": ">=3.1.31"
50-
},
5147
"prettier": "@ivangabriele/prettier-config",
5248
"release": {
5349
"extends": "@ivangabriele/semantic-release-config-base"

0 commit comments

Comments
 (0)