Skip to content

Commit

Permalink
feat: shared Repository test suite
Browse files Browse the repository at this point in the history
Creates infrastructure for writing tests for different `Repositiory`
interfaces and executing them against different Repository
implementations (e.g. `DefaultCrudRepository` and `CrudRepositoryImpl`)
and different databases (e.g. `MongoDB` and `MySQL`).

The initial version of the shared test suite has only two very basic
test cases to verify the testing infrastructure. My intention is to move
relevant tests from `packages/repository/src/__tests__` to the new test
suite later.
  • Loading branch information
bajtos committed Jun 18, 2019
1 parent abda918 commit e2a04c7
Show file tree
Hide file tree
Showing 48 changed files with 2,337 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@ npm-debug.log
coverage
.nyc_output
**/*.tgz
acceptance/*/dist
packages/*/dist
examples/*/dist
benchmark/dist
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -7,6 +7,7 @@ packages/tsdocs/fixtures/monorepo/docs
packages/tsdocs/fixtures/monorepo/**/dist
packages/tsdocs/fixtures/monorepo/**/docs
**/.sandbox
acceptance/*/dist
packages/*/dist
examples/*/dist
benchmark/dist
Expand Down
27 changes: 27 additions & 0 deletions .travis.yml
Expand Up @@ -40,6 +40,33 @@ matrix:
os: linux
env: TASK=verify-docs
script: ./bin/verify-doc-changes.sh
- node_js: "10"
os: linux
env:
- TASK=test-repository-mongodb
services:
- mongodb
script:
- npm run postinstall -- --scope "@loopback/test-repository-mongodb" --include-filtered-dependencies
- npm run build -- --scope "@loopback/test-repository-mongodb" --include-filtered-dependencies
- cd acceptance/repository-mongodb && npm run mocha
- node_js: "10"
os: linux
env:
- TASK=test-repository-mysql
- MYSQL_USER=test
- MYSQL_PASSWORD=test
services:
- mysql
before_install:
- mysql -u root -e "CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';"
- mysql -e "use mysql; update user set authentication_string=PASSWORD('test') where User='test'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION;FLUSH PRIVILEGES;"
- mysql -e "GRANT SUPER ON *.* TO 'test'@'localhost' IDENTIFIED BY 'test';FLUSH PRIVILEGES;"
script:
- npm run postinstall -- --scope "@loopback/test-repository-mysql" --include-filtered-dependencies
- npm run build -- --scope "@loopback/test-repository-mysql" --include-filtered-dependencies
- cd acceptance/repository-mysql && npm run mocha

branches:
only:
Expand Down
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -6,6 +6,8 @@

* @bajtos @raymondfeng

acceptance/repository-mongodb/* @bajtos
acceptance/repository-mysql/* @bajtos
packages/authentication/* @bajtos @raymondfeng
packages/boot/* @raymondfeng @hacksparrow
packages/booter-lb3app/* @bajtos @nabdelgadir
Expand All @@ -21,6 +23,7 @@ packages/openapi-spec-builder/* @bajtos @raymondfeng
packages/openapi-v3/* @bajtos @jannyHou
packages/openapi-v3-types/* @bajtos @jannyHou
packages/repository/* @raymondfeng
packages/repository-tests/* @bajtos
packages/repository-json-schema/* @bajtos
packages/rest/* @bajtos @raymondfeng
packages/service-proxy/* @raymondfeng
Expand Down
5 changes: 5 additions & 0 deletions acceptance/README.md
@@ -0,0 +1,5 @@
## Acceptance tests

This directory contains packages with acceptance-level tests. These tests are
not invoked as part of root `npm test`, you have to run them manually. Consult
README files of individual packages for instructions on how to run the tests.
1 change: 1 addition & 0 deletions acceptance/repository-mongodb/.npmrc
@@ -0,0 +1 @@
package-lock=true
25 changes: 25 additions & 0 deletions acceptance/repository-mongodb/LICENSE
@@ -0,0 +1,25 @@
Copyright (c) IBM Corp. 2017,2019. All Rights Reserved.
Node module: @loopback/test-repository-mongodb
This project is licensed under the MIT License, full text below.

--------

MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
63 changes: 63 additions & 0 deletions acceptance/repository-mongodb/README.md
@@ -0,0 +1,63 @@
# @loopback/test-repository-mongodb

Acceptance tests for `@loopback/repository` + `loopback-connector-mongodb`.

## Running the test suite

### Using own MongoDB instance

If you have a local MongoDB instance listening on `localhost` and the default
port, use the following command:

```bash
npm test
```

If you have a local or remote MongoDB instance and would like to use that to run
the test suite, use the following command:

**Linux & MacOS**

```bash
MONGODB_HOST=<HOST> MONGODB_PORT=<PORT> MONGODB_DATABASE=<DATABASE> npm test
```

**Windows**

```bash
SET MONGODB_HOST=<HOST>
SET MONGODB_PORT=<PORT>
SET MONGODB_DATABASE=<DATABASE>
npm test
```

### Using Docker (Linux, MacOS, WSL)

If you do not have a local MongoDB instance, you can also run the test suite
with very minimal requirements.

- Assuming you have [Docker](https://docs.docker.com/engine/installation/)
installed, run the following script which would spawn a MongoDB instance on
your local:

```bash
source setup.sh <HOST> <PORT> <DATABASE>
```

Where `<HOST>`, `<PORT>` and `<DATABASE>` are optional parameters. The default
values are `localhost`, `27017` and `testdb` respectively.

- Run the test:

```bash
npm test
```

## Contributors

See
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).

## License

MIT
6 changes: 6 additions & 0 deletions acceptance/repository-mongodb/index.d.ts
@@ -0,0 +1,6 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/test-repository-mongodb
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

export * from './dist';
6 changes: 6 additions & 0 deletions acceptance/repository-mongodb/index.js
@@ -0,0 +1,6 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/test-repository-mongodb
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

module.exports = require('./dist');
8 changes: 8 additions & 0 deletions acceptance/repository-mongodb/index.ts
@@ -0,0 +1,8 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/test-repository-mongodb
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

// DO NOT EDIT THIS FILE
// Add any additional (re)exports to src/index.ts instead.
export * from './src';

0 comments on commit e2a04c7

Please sign in to comment.