Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPM & no lerna test #768

Open
wants to merge 7 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
"cucumberautocomplete.strictGherkinCompletion": true,
"python.analysis.extraPaths": [
"./packages/python-runner/__pypackages__"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext"
],
"spellright.language": [
"en"
]
}
32 changes: 4 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ It currently supports Node.js based apps, but Python and other languages are com
- [Docker commands :whale:](#docker-commands-whale)
- [Build Hub on Docker :building_construction:](#build-hub-on-docker-building_construction)
- [Run Transform Hub in Docker :robot:](#run-transform-hub-in-docker-robot)
- [Lerna commands :pencil:](#lerna-commands-pencil)
- [Autocomplete :zap:](#autocomplete-zap)
- [Git branching workflow](#git-branching-workflow)
- [Sample usage :sunglasses:](#sample-usage-sunglasses)
Expand Down Expand Up @@ -151,7 +150,6 @@ There are several installations you need to perform to get STH up and running, a

- nvm
- node.js
- lerna
- yarn
- typescript
- ts-node
Expand All @@ -168,7 +166,7 @@ npm -v

If none of the above commands is found, **you must proceed with the installation.**

It is recommended to use a **Node version manager** like [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md) to install Node.js and npm. Do it by running the install script using either of the commands bellow.
It is recommended to use a **Node version manager** like [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md) to install Node.js and npm. Do it by running the install script using either of the commands bellow.
> Note: Make sure you replace v0.39.0 with the latest version of nvm. The actual version of nvm to install is [here](https://github.com/nvm-sh/nvm/blob/master/README.md#install--update-script).

```bash
Expand Down Expand Up @@ -216,12 +214,11 @@ $ npm -v
8.15.0
```

**OK!** It looks like you have successfully installed node.js and npm.
**OK!** It looks like you have successfully installed node.js and npm.

There are two more installations you need to perform, run the following commands in your console one after another:

```bash
npm install -g lerna # lerna is a tool that we use for publishing multiple packages to npm.
npm install -g yarn # yarn is a package manager
```

Expand All @@ -230,9 +227,6 @@ npm install -g yarn # yarn is a package manager
The same as before the installations can be confirmed by checking the installed versions:

```bash
$ lerna -v
4.0.0

$ yarn -v
1.22.17
```
Expand Down Expand Up @@ -301,7 +295,7 @@ In the meantime let me describe for you what is happening in the command you hav

When both the package installation and build are complete, STH should be ready to run.



---

Expand Down Expand Up @@ -491,24 +485,6 @@ docker run \
scramjetorg/sth:$(jq -r .version package.json)
```

## Lerna commands :pencil:

We use Lerna to control our monorepo. Here's a couple of helpful commands, which might be useful during development:

```bash
lerna create package_name # Add new package:
lerna ls # List all of the public packages in the current Lerna repo:
lerna run [script] # Run an npm script in each package that contains that script.
lerna run --ignore @scramjet/<package_name> <script-name>
# Run script in all packages excluding one package:
lerna run --ignore @scramjet/<package_name> --ignore @scramjet/<package_name> <script-name>
# ... or run script excluding more packages
lerna run --scope @scramjet/<package_name> <script-name>
# Run script only in one package
lerna run --scope @scramjet/<package_name> --scope @scramjet/<package_name> <script-name>
# Run script in more packages
```

## Autocomplete :zap:

Completion script depends on bash-completion so make sure it's already installed by running `type _init_completion`.
Expand Down Expand Up @@ -700,7 +676,7 @@ It will build all the packages in the `packages/reference-apps` folder.

</details><br>

> **💡 HINT:** Have a look at the root `package.json`, there is the `scripts` section, which contains the list of all the scripts you can run with lerna. You may find them useful.
> **💡 HINT:** Have a look at the root `package.json`, there is the `scripts` section, which contains the list of all the scripts you can run with yarn or npm. You may find them useful.

Log an issue/bug every time you encounter a problem or find a bug. Maybe you will also find that some feature is missing?

Expand Down
126 changes: 92 additions & 34 deletions bdd/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Behavior Driven Development
# Behaviour Driven Development

As the "problem scope" of the business problem that our technology solves is quite complex, we decided to use the BDD practice to support the development process. BDD is a methodology of high automation and agility. It describes a cycle of interactions with well-defined outcomes. As a result of these activities, we obtain working, tested software that has a real value.
As the "problem scope" of the business problem that our technology solves is quite complex, we decided to use the BDD practice to support the development process. BDD is a methodology of high automation and agility. It describes a cycle of interactions with well-defined outcomes. As a result of these activities, we obtain working, tested software that has real value.

We use [Cucumber](https://cucumber.io/) as a software tool to support the BDD process and [Gherkin](https://cucumber.io/docs/gherkin/) syntax that allows us to write tests in a human-readable language.

Expand Down Expand Up @@ -34,12 +34,12 @@ Before start running any test, please make sure that all the packages are instal
yarn clean && yarn install && yarn build:all
```

This command will remove all the 'dist' folders (if there were any), after that it will install dependencies, compile the code in all the packages including 'reference-apps' package, which contains all the Sequences that we use in our BDD tests. After executing the command from above, every Sequence will be also compressed into `.tar.gz` file. Those compressed files are ready-to-use Sequence packages, that we use in BDD tests scenarios.
This command will remove all the `'dist'` folders (if there were any), after that it will install dependencies, and compile the code in all the packages including `'reference-apps'` package, which contains all the Sequences that we use in our BDD tests. After executing the command from above, every Sequence will be also compressed into `.tar.gz` file. Those compressed files are ready-to-use Sequence packages, that we use in BDD test scenarios.

### Executing BDD tests :rocket:

The test scenarios are located in `*.feature` files, and these in separate folders named according to the subject of the testing, and these in `features` directory in `bdd` folder.
Every scenario has its own title and unique index number. We can use those indexes to either execute one test or a bulk of tests, for example:
The test scenarios are located in `*.feature` files, and these are in separate folders named according to the subject of the testing, and these in `features` directory in `bdd` folder.
Every scenario has its title and unique index number. We can use those indexes to either execute one test or bulk of tests, for example:

- to execute one particular test named `Scenario: E2E-001 TC-002 API test - Get instance output` run the following command:

Expand All @@ -53,7 +53,7 @@ This is the output after running this single test:

![test1.png](../images/test1.png)

- to execute a bulk of scenarios, for example from the same feature file, you can simply use the substring of their index like "E2E-001", run the following command:
- to execute a bulk of scenarios, for example from the same feature file, you can simply use the substring of their index like "E2E-001", and run the following command:

```bash
yarn test:bdd --name="E2E-001"
Expand All @@ -77,27 +77,27 @@ yarn test:BDD --name="E2E"
yarn test:bdd --tags="@ci"
```

The list of scenarios marked with `@ci` tag is quite long so I will paste only start of the test and the summary of the test execution:
The list of scenarios marked with `@ci` tag is quite long so I will paste only the start of the test and the summary of the test execution:

![test_ci.png](../images/test_ci.png)

(...)

![test3.png](../images/test3.png)

Scenario can have more that one tag, can have two or even more, for example:
A scenario can have more thatn one tag, can have two or even more, for example:

![tags.png](../images/tags.png)

In the situation like this above, when you want to execute tests with `@ci` tag but without `@starts-host` tag, command like this below will do the job:
In the situation like this above, when you want to execute tests with `@ci` tag but without `@starts-host` tag, a command like this below will do the job:

```bash
yarn test:bdd --tags="@ci" --tags="not @starts-host"
```

### Results :bar_chart:

The results of the performed test will be displayed in the console as a summary of executed tests. There is also a report generated in `html` which illustrates the results in a very user friendly form. Html report is generated every time we run a BDD test, those html's are saved in `bdd/reports` folder.
The results of the performed test will be displayed in the console as a summary of executed tests. There is also a report generated in `html` which illustrates the results in a very user-friendly form. Html report is generated every time we run a BDD test, those html's are saved in `bdd/reports` folder.

## Shell variables :shell: :computer:

Expand All @@ -116,38 +116,96 @@ With the command below you will run all the unit tests in a whole project:

yarn test

This command runs `test` script defined in the main `package.json` [file](../package.json). The script executes lerna command: `lerna run test`. In a result, lerna goes through all the packages and runs unit tests in every package.
This command runs `test` script defined in the main `package.json` [file](../package.json). In result, the script goes through all the packages and runs unit tests in every package.

If you see the error along the way, that means some tests were not passed.

Below you can see an example, which shows the result of all passed unit test in all the packages:
Below you can see an example, which shows the result of all passed unit tests in all the packages:

```bash
lerna success run Ran npm script 'test' in 17 packages in 40.2s:
lerna success - @scramjet/adapters
lerna success - @scramjet/api-client
lerna success - @scramjet/api-server
lerna success - @scramjet/cli
lerna success - @scramjet/host
lerna success - @scramjet/load-check
lerna success - @scramjet/logger
lerna success - @scramjet/model
lerna success - @scramjet/pre-runner
lerna success - @scramjet/runner
lerna success - @scramjet/sth-config
lerna success - @scramjet/sth
lerna success - @scramjet/symbols
lerna success - @scramjet/test-ava-ts-node
lerna success - @scramjet/types
lerna success - @scramjet/utility
Done in 40.76s.
yarn test
# yarn run v1.22.19
# yarn test:packages
# $scripts/run-script.js test
# run-script: 3.791s packages/client-utils: script test executed in 3775ms.
# run-script: 4.059s packages/adapters: script test executed in 4044ms.
# run-script: 4.518s packages/api-client: script test executed in 4502ms.
# run-script: 6.072s packages/cli: script test executed in 6056ms.
# run-script: 6.991s packages/host: script test executed in 6976ms.
# run-script: 7.343s packages/api-server: script test executed in 7327ms.
# run-script: 8.332s packages/load-check: script test executed in 4272ms.
# run-script: 8.659s packages/obj-logger: script test executed in 327ms.
# run-script: 8.772s packages/logger: script test executed in 4253ms.
# run-script: 8.780s packages/pre-runner: script test executed in 8ms.
# run-script: 9.570s packages/manager-api-client: script test executed in 2227ms.
# run-script: 9.600s packages/middleware-api-client: script test executed in 2256ms.
# run-script: 9.609s packages/multi-manager-api-client: script test executed in 2265ms.
# run-script: 11.378s packages/model: script test executed in 4034ms.
# run-script: 11.408s packages/telemetry: script test executed in 30ms.
# run-script: 11.409s packages/sth: script test executed in 30ms.
# run-script: 14.450s packages/sth-config: script test executed in 3071ms.
# run-script: 14.450s packages/symbols: script test executed in 3071ms.
# run-script: 14.743s packages/utility: script test failed with code=1!
# packages/utility: command was: "npm run test:ava"
#
# > @scramjet/utility@0.31.2 test:ava
# > ava
#
#
# ✔ host › merge() should overwrite primitive values
# ✔ host › merge() should deeply merge object values
# ✔ host › merge() objFrom argument type should only allow deep partial
# ✖ configFileDefault › Default file returned on invalid file path Error thrown in test
# ✔ configFileDefault › Default config returned on invalid config in file
# ✔ configFileDefault › Config returned on valid config in file
# ✔ configFileDefault › Restore default configuration
# ─
#
# configFileDefault › Default file returned on invalid file path
#
# test/configFileDefault.spec.ts:26
#
# 25: constructor(path: string) {
# 26: super(path, testDefaultConfig);
# 27: }
#
# Error thrown in test:
#
# Error {
# code: 'ENOENT',
# errno: -2,
# syscall: 'open',
# message: 'ENOENT: no such file or directory, open',
# }
#
# › TextFile.write (src/file/textFile.ts:12:45)
# › TextFile.create (src/file/textFile.ts:34:14)
# › TestConfigFileDefault.createIfNotExistAndWrite (src/config/configFile.ts:34:45)
# › TestConfigFileDefault.set (src/config/configFile.ts:42:21)
# › new ConfigFile (src/config/configFile.ts:20:14)
# › new ConfigFileDefault (src/config/configFileDefault.ts:11:9)
# › new TestConfigFileDefault (test/configFileDefault.spec.ts:26:9)
# › test/configFileDefault.spec.ts:83:24
#
# ─
#
# 1 test failed
#
# npm ERR! Lifecycle script `test:ava` failed with error:
# npm ERR! Error: command failed
# npm ERR! in workspace: @scramjet/utility@0.31.2
# npm ERR! at location: /home/mczapracki/src/scramjetorg/transform-hub/packages/utility
#
# run-script: 15.340s packages/types: script test executed in 3961ms.
# run-script: 15.740s packages/verser: script test executed in 4330ms.
# Done in 16.19s.
```

If you want to run a particular test file, go to directory where the test file is and run command:
If you want to run a particular test file, go to the directory where the test file is and run this command:

npx ava

For example if you want to run unit test for the Runner package, go to runner's test directory and run the test:
For example, if you want to run unit tests for the Runner package, go to runner's test directory and run the test:

cd packages/runner/test
npx ava
Expand All @@ -156,7 +214,7 @@ and you will see the results in the console:

![ava](../images/ava.png)

If you want to run one particular test in the file, go to directory where the test file is and run command:
If you want to run one particular test in the file, go to the directory where the test file is and run this command:

npx ava name-of-the-file.spec.ts -m "Name-of-the-unit-test"

Expand All @@ -166,6 +224,6 @@ for example:

![ava1](../images/ava1.png)

If you add `-w` a the end of the command above the test will run automatically after every change you make in the test, eg.:
If you add `-w` a the end of the command above the test will run automatically after every change you make in the test, e.g.:

npx ava runner.spec.ts -m "Stop sequence" -w
33 changes: 3 additions & 30 deletions docs/sth-constants/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ It currently supports Node.js based apps, but Python and other languages are com
- [Docker commands :whale:](#docker-commands-whale)
- [Build Hub on Docker :building_construction:](#build-hub-on-docker-building_construction)
- [Run Transform Hub in Docker :robot:](#run-transform-hub-in-docker-robot)
- [Lerna commands :pencil:](#lerna-commands-pencil)
- [Autocomplete :zap:](#autocomplete-zap)
- [Sample usage :sunglasses:](#sample-usage-sunglasses)
- ["Hello Alice" sample :wave:](#hello-alice-sample-wave)
Expand Down Expand Up @@ -149,7 +148,6 @@ There are several installations you need to perform to get STH up and running, a

- nvm
- node.js
- lerna
- yarn
- typescript
- ts-node
Expand Down Expand Up @@ -219,7 +217,6 @@ output: `8.1.0`
OK! It looks like you have successfully installed node.js and npm. There are two more installations you need to perform, run the following commands in your console one after another:

```bash
npm install -g lerna
npm install -g yarn
```

Expand Down Expand Up @@ -463,24 +460,6 @@ docker run \
scramjetorg/sth:$(jq -r .version package.json)
```

## Lerna commands :pencil:

We use Lerna to control our monorepo. Here's a couple of helpful commands, which might be useful during development:

```bash
lerna create package_name # Add new package:
lerna ls # List all of the public packages in the current Lerna repo:
lerna run [script] # Run an npm script in each package that contains that script.
lerna run --ignore @scramjet/<package_name> <script-name>
# Run script in all packages excluding one package:
lerna run --ignore @scramjet/<package_name> --ignore @scramjet/<package_name> <script-name>
# ... or run script excluding more packages
lerna run --scope @scramjet/<package_name> <script-name>
# Run script only in one package
lerna run --scope @scramjet/<package_name> --scope @scramjet/<package_name> <script-name>
# Run script in more packages
```

## Autocomplete :zap:

Completion script depends on bash-completion so make sure it's already installed by running `type _init_completion`.
Expand Down Expand Up @@ -520,16 +499,10 @@ The Sequence needs to be compressed into a `tar.gz` file format before we send i
Assuming that you have the [host running](#start-the-hub-checkered_flag) use the command:

```bash
yarn build:refapps # this builds all the refapps in the 'reference-apps' package
```

When the host is not running you can use a script:

```bash
lerna run prepare-sample-tar
yarn download:refapps # this downloads all the refapps from the 'reference-apps' package
```

To compress specific package use linux tar command:
To compress specific package use Linux tar command:

```bash
tar -C /path/to/package/dir czf <package-name.tar.gz> .
Expand Down Expand Up @@ -703,7 +676,7 @@ It will build all the packages in the `packages/reference-apps` folder.

</details><br>

> **💡 HINT:** Have a look at the root `package.json`, there is the `scripts` section, which contains the list of all the scripts you can run with lerna. You may find them useful.
> **💡 HINT:** Have a look at the root `package.json`, there is the `scripts` section, which contains the list of all the scripts you can run with yarn or npm. You may find them useful.

Log an issue/bug every time you encounter a problem or find a bug. Maybe you will also find that some feature is missing?

Expand Down
Loading