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

Commit

Permalink
test(e2e): migrate to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Jan 23, 2022
1 parent 5daa86a commit 64963bc
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 809 deletions.
21 changes: 6 additions & 15 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,16 @@
},
"overrides": [
{
"files": ["./src/**/*.test.ts", "./tests/**/*.js"],
"plugins": ["jest"],
"env": {
"jest/globals": true
}
},
{
"files": ["./e2e/**/*.js"],
"env": {
"mocha": true
},
"files": ["./scripts/**/*.js", "./tests/**/*.js"],
"rules": {
"import/no-unresolved": "off"
"import/no-extraneous-dependencies": "off"
}
},
{
"files": ["./e2e/**/*.js", "./scripts/**/*.js", "./tests/**/*.js"],
"rules": {
"import/no-extraneous-dependencies": "off"
"files": ["./e2e/**/*.js", "./src/**/*.test.ts", "./tests/**/*.js"],
"plugins": ["jest"],
"env": {
"jest/globals": true
}
}
]
Expand Down
50 changes: 22 additions & 28 deletions e2e/delete.spec.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
const assert = require('assert')

// eslint-disable-next-line import/no-unresolved
const { create } = require('..')
const handleError = require('./helpers/handleError')

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

describe('E2E: #delete()', () => {
it(`should return undefined with a single item and no option`, async () => {
try {
await postgrestClient.post('/customers', {
email: '[email protected]',
name: 'Bob Marley',
})
const result = await postgrestClient.eq('email', '[email protected]').delete('/customers')
beforeEach(async () => {
await postgrestClient.delete('/customers')
})

test(`should return undefined with a single item and no option`, async () => {
await postgrestClient.post('/customers', {
email: '[email protected]',
name: 'Bob Marley',
})
const result = await postgrestClient.eq('email', '[email protected]').delete('/customers')

assert.equal(result.data, undefined)
} catch (err) {
handleError(err)
}
expect(result.data).toBeUndefined()
})

it(`should return undefined with a single item and no option`, async () => {
try {
await postgrestClient.post('/customers', {
email: '[email protected]',
name: 'Bob Marley',
})
const result = await postgrestClient.eq('email', '[email protected]').delete('/customers', {
return: 'representation',
})
test(`should return undefined with a single item and { return: "representation" }`, async () => {
await postgrestClient.post('/customers', {
email: '[email protected]',
name: 'Bob Marley',
})
const result = await postgrestClient.eq('email', '[email protected]').delete('/customers', {
return: 'representation',
})

assert.equal(result.data.email, '[email protected]')
assert.equal(result.data.name, 'Bob Marley')
} catch (err) {
handleError(err)
}
expect(result.data.email).toEqual('[email protected]')
expect(result.data.name).toEqual('Bob Marley')
})
})
15 changes: 0 additions & 15 deletions e2e/helpers/handleError.js

This file was deleted.

19 changes: 9 additions & 10 deletions e2e/ilike.spec.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
const assert = require('assert')

// eslint-disable-next-line import/no-unresolved
const { create } = require('..')

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

describe('E2E: #ilike()', () => {
it(`should find all the books which title contains "an" or "An"`, async () => {
test(`should find all the books which title contains "an" or "An"`, async () => {
const { data: result } = await postgrestClient
.select('title')
.select('authors(name)')
.ilike('title', 'an')
.orderBy('title')
.get('/books')

assert.equal(result.length, 3)
assert.equal(result[0].title, "An Analysis of Betty Friedan's The Feminine Mystique")
assert.equal(result[0].authors.name, 'Elizabeth Whitaker')
assert.equal(result[1].title, 'Anna Karenina')
assert.equal(result[1].authors.name, 'Leo Tolstoy')
assert.equal(result[2].title, 'War and Peace')
assert.equal(result[2].authors.name, 'Leo Tolstoy')
expect(result.length).toEqual(3)
expect(result[0].title).toEqual("An Analysis of Betty Friedan's The Feminine Mystique")
expect(result[0].authors.name).toEqual('Elizabeth Whitaker')
expect(result[1].title).toEqual('Anna Karenina')
expect(result[1].authors.name).toEqual('Leo Tolstoy')
expect(result[2].title).toEqual('War and Peace')
expect(result[2].authors.name).toEqual('Leo Tolstoy')
})
})
23 changes: 11 additions & 12 deletions e2e/like.spec.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
const assert = require('assert')

// eslint-disable-next-line import/no-unresolved
const { create } = require('..')

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

describe('E2E: #like()', () => {
it(`should find all the books which title contains "u"`, async () => {
test(`should find all the books which title contains "u"`, async () => {
const { data: result } = await postgrestClient
.select('title')
.select('authors(name)')
.like('title', 'u')
.orderBy('title')
.get('/books')

assert.equal(result.length, 2)
assert.equal(result[0].title, "An Analysis of Betty Friedan's The Feminine Mystique")
assert.equal(result[0].authors.name, 'Elizabeth Whitaker')
assert.equal(result[1].title, 'Crow Blue')
assert.equal(result[1].authors.name, 'Adriana Lisboa')
expect(result.length).toEqual(2)
expect(result[0].title).toEqual("An Analysis of Betty Friedan's The Feminine Mystique")
expect(result[0].authors.name).toEqual('Elizabeth Whitaker')
expect(result[1].title).toEqual('Crow Blue')
expect(result[1].authors.name).toEqual('Adriana Lisboa')
})

it(`should find all the books which title contains "U"`, async () => {
test(`should find all the books which title contains "U"`, async () => {
const { data: result } = await postgrestClient
.select('title')
.select('authors(name)')
.like('title', 'U')
.orderBy('title')
.get('/books')

assert.equal(result.length, 1)
assert.equal(result[0].title, 'The Unbearable Lightness of Being')
assert.equal(result[0].authors.name, 'Milan Kundera')
expect(result.length).toEqual(1)
expect(result[0].title).toEqual('The Unbearable Lightness of Being')
expect(result[0].authors.name).toEqual('Milan Kundera')
})
})
94 changes: 40 additions & 54 deletions e2e/post.spec.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,62 @@
const assert = require('assert')

// eslint-disable-next-line import/no-unresolved
const { create } = require('..')
const handleError = require('./helpers/handleError')

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

describe('E2E: #post()', () => {
beforeEach(async () => {
await postgrestClient.gt('id', 1).delete('/customers')
await postgrestClient.delete('/customers')
})

test(`should return undefined with a single item and no option`, async () => {
const result = await postgrestClient.post('/customers', {
email: '[email protected]',
name: 'Bob Marley',
})

expect(result.data).toBeUndefined()
})

it(`should return undefined with a single item and no option`, async () => {
try {
const result = await postgrestClient.post('/customers', {
test(`should return the created row with a single item and { return: "representation" }`, async () => {
const result = await postgrestClient.post(
'/customers',
{
email: '[email protected]',
name: 'Bob Marley',
})

assert.equal(result.data, undefined)
} catch (err) {
handleError(err)
}
},
{
return: 'representation',
},
)

expect(result.data.email).toEqual('[email protected]')
expect(result.data.name).toEqual('Bob Marley')
})

it(`should return the created row with a single item and { return: "representation" }`, async () => {
try {
const result = await postgrestClient.post(
'/customers',
test(`should return the created rows with multiple items and { return: "representation" }`, async () => {
const result = await postgrestClient.post(
'/customers',
[
{
email: '[email protected]',
name: 'Bob Marley',
},
{
return: 'representation',
email: '[email protected]',
name: 'Bob Sinclar',
},
)

assert.equal(result.data.email, '[email protected]')
assert.equal(result.data.name, 'Bob Marley')
} catch (err) {
handleError(err)
}
})

it(`should return the created rows with multiple items and { return: "representation" }`, async () => {
try {
const result = await postgrestClient.post(
'/customers',
[
{
email: '[email protected]',
name: 'Bob Marley',
},
{
email: '[email protected]',
name: 'Bob Sinclar',
},
],
{
return: 'representation',
},
)

assert.equal(result.data.length, 2)
assert.equal(result.data[0].email, '[email protected]')
assert.equal(result.data[0].name, 'Bob Marley')
assert.equal(result.data[1].email, '[email protected]')
assert.equal(result.data[1].name, 'Bob Sinclar')
} catch (err) {
handleError(err)
}
],
{
return: 'representation',
},
)

expect(result.data.length).toEqual(2)
expect(result.data[0].email).toEqual('[email protected]')
expect(result.data[0].name).toEqual('Bob Marley')
expect(result.data[1].email).toEqual('[email protected]')
expect(result.data[1].name).toEqual('Bob Sinclar')
})
})
6 changes: 6 additions & 0 deletions jest.e2e.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
bail: true,
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
roots: ['<rootDir>/e2e'],
verbose: true,
}
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prepare": "husky install",
"setup": "node ./scripts/dev/setup.js",
"test": "yarn test:lint && yarn test:unit",
"test:e2e": "yarn build && mocha -b ./e2e/*.spec.js",
"test:e2e": "yarn build && jest -c ./jest.e2e.config.js --runInBand",
"test:e2e:v8": "cross-env POSTGREST_VERSION=v8.0.0.20211102 yarn setup && yarn test:e2e",
"test:e2e:v9": "yarn setup && yarn test:e2e",
"test:lint": "eslint .",
Expand All @@ -38,16 +38,12 @@
"husky": "7.0.4",
"jest": "27.4.7",
"knex": "1.0.1",
"mocha": "9.1.4",
"pg": "8.7.1",
"rollup": "2.66.0",
"shelljs": "0.8.5",
"ts-jest": "27.1.3",
"typescript": "4.5.5"
},
"resolutions": {
"nanoid": ">=3.1.31"
},
"prettier": "@ivangabriele/prettier-config",
"release": {
"extends": "@ivangabriele/semantic-release-config-base"
Expand Down
Loading

0 comments on commit 64963bc

Please sign in to comment.