From 97893fed1bd1a227d0b12ac1448eb864e033ead8 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Wed, 14 Aug 2019 13:45:18 +0200 Subject: [PATCH] :books: Update development cycle documentation and add placeholder tests --- CONTRIBUTING.md | 45 +++++++++++++------ package.json | 1 + packages/cli/test/placeholder.test.ts | 7 +++ packages/editor-ui/package.json | 1 + packages/editor-ui/tests/unit/example.spec.ts | 12 ----- .../editor-ui/tests/unit/placeholder.spec.ts | 5 +++ packages/node-dev/package.json | 19 ++++++++ packages/node-dev/test/placeholder.test.ts | 7 +++ packages/node-dev/tsconfig.json | 4 +- packages/nodes-base/test/placeholder.test.ts | 7 +++ 10 files changed, 82 insertions(+), 26 deletions(-) create mode 100644 packages/cli/test/placeholder.test.ts delete mode 100644 packages/editor-ui/tests/unit/example.spec.ts create mode 100644 packages/editor-ui/tests/unit/placeholder.spec.ts create mode 100644 packages/node-dev/test/placeholder.test.ts create mode 100644 packages/nodes-base/test/placeholder.test.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 36ad6cf336..576dc387df 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,10 +42,7 @@ dependencies are installed and the packages get linked correctly. Here a short g #### Build Tools -That all the packages which n8n uses can be installed and compiled correctly -the essential build tools must be installed. This is probably already the case -for the most people but if you are totally new to development or just setting -up a new computer it is probably still missing. +The packages which n8n uses depend on a few build tools: Linux: ``` @@ -60,7 +57,7 @@ npm install -g windows-build-tools #### lerna n8n is split up in different modules which are all in a single mono repository. -To make development as easy as possible does [lerna](https://lerna.js.org) get +To facilitate those modules management, [lerna](https://lerna.js.org) gets used. It automatically sets up file-links between modules which depend on each other. @@ -81,17 +78,17 @@ checked out and set up: git clone https://github.com/n8n-io/n8n.git ``` -2. Go into repository folder +1. Go into repository folder ``` cd n8n ``` -3. Install all dependencies of all modules and link them together: +1. Install all dependencies of all modules and link them together: ``` lerna bootstrap --hoist ``` -4. Build all the code: +1. Build all the code: ``` npm run build ``` @@ -109,13 +106,35 @@ npm run start ## Development Cycle -While iterating on n8n modules' code, you can run `npm run watch` to automatically build your changes. This will alert you as soon as something gets broken. +While iterating on n8n modules code, you can run `npm run dev`. It will then +automatically build your code, restart the backend and refresh the frontend +(editor-ui) on every change you make. -1. `npm run watch` +1. Start n8n in development mode: + ``` + npm run dev + ``` 1. hack, hack, hack -1. `npm run start` -1. test +1. Check if everything still runs in production mode + ``` + npm run build + npm run start + ``` +1. Create tests +1. Run all tests + ``` + npm run test + ``` +1. Commit code and create pull request + ### Test suite -TODO: how to run jest or other automated test tools +The tests can be started via: +``` +npm run test +``` + +If that gets executed in one of the package folders it will only run the tests +of this package. If it gets executed in the n8n-root folder it will run all +tests of all packages. diff --git a/package.json b/package.json index efb658e2eb..f557ffb9f7 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "build": "lerna exec npm run build", "dev": "lerna exec npm run dev --parallel", "start": "cd packages/cli && node dist/index.js start", + "test": "lerna run test", "watch": "lerna run --parallel watch" }, "devDependencies": { diff --git a/packages/cli/test/placeholder.test.ts b/packages/cli/test/placeholder.test.ts new file mode 100644 index 0000000000..23ba06a64f --- /dev/null +++ b/packages/cli/test/placeholder.test.ts @@ -0,0 +1,7 @@ +describe('Placeholder', () => { + + test('example', () => { + expect(1 + 1).toEqual(2); + }); + +}); diff --git a/packages/editor-ui/package.json b/packages/editor-ui/package.json index 72da793cb8..e13f0244d3 100644 --- a/packages/editor-ui/package.json +++ b/packages/editor-ui/package.json @@ -16,6 +16,7 @@ "dev": "npm run serve", "lint": "vue-cli-service lint", "serve": "VUE_APP_URL_BASE_API=http://localhost:5678/ vue-cli-service serve", + "test": "npm run test:unit", "tslint": "tslint -p tsconfig.json -c tslint.json", "test:e2e": "vue-cli-service test:e2e", "test:unit": "vue-cli-service test:unit" diff --git a/packages/editor-ui/tests/unit/example.spec.ts b/packages/editor-ui/tests/unit/example.spec.ts deleted file mode 100644 index b8005575be..0000000000 --- a/packages/editor-ui/tests/unit/example.spec.ts +++ /dev/null @@ -1,12 +0,0 @@ -// import { shallowMount } from '@vue/test-utils'; -// import HelloWorld from '@/components/HelloWorld.vue'; - -// describe('HelloWorld.vue', () => { -// it('renders props.msg when passed', () => { -// const msg = 'new message'; -// const wrapper = shallowMount(HelloWorld, { -// propsData: { msg } -// }); -// expect(wrapper.text()).toMatch(msg); -// }); -// }); diff --git a/packages/editor-ui/tests/unit/placeholder.spec.ts b/packages/editor-ui/tests/unit/placeholder.spec.ts new file mode 100644 index 0000000000..21c4bf29eb --- /dev/null +++ b/packages/editor-ui/tests/unit/placeholder.spec.ts @@ -0,0 +1,5 @@ +describe('Placeholder.vue', () => { + it('example', () => { + expect(1 + 1).toEqual(2); + }); +}); diff --git a/packages/node-dev/package.json b/packages/node-dev/package.json index bd31087268..b1ecdb2fac 100644 --- a/packages/node-dev/package.json +++ b/packages/node-dev/package.json @@ -16,6 +16,7 @@ "scripts": { "dev": "npm run watch", "build": "tsc", + "test": "jest", "tslint": "tslint -p tsconfig.json -c tslint.json", "watch": "tsc --watch" }, @@ -45,5 +46,23 @@ "replace-in-file": "^4.1.0", "typescript": "~3.5.2", "vorpal": "^1.12.0" + }, + "jest": { + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "testURL": "http://localhost/", + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "testPathIgnorePatterns": [ + "/dist/", + "/node_modules/" + ], + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "json", + "node" + ] } } diff --git a/packages/node-dev/test/placeholder.test.ts b/packages/node-dev/test/placeholder.test.ts new file mode 100644 index 0000000000..23ba06a64f --- /dev/null +++ b/packages/node-dev/test/placeholder.test.ts @@ -0,0 +1,7 @@ +describe('Placeholder', () => { + + test('example', () => { + expect(1 + 1).toEqual(2); + }); + +}); diff --git a/packages/node-dev/tsconfig.json b/packages/node-dev/tsconfig.json index 97c769b1bd..cfc2e2af1c 100644 --- a/packages/node-dev/tsconfig.json +++ b/packages/node-dev/tsconfig.json @@ -4,7 +4,8 @@ "es2017" ], "types": [ - "node" + "node", + "jest" ], "module": "commonjs", "esModuleInterop": true, @@ -26,6 +27,7 @@ ], "exclude": [ "dist", + "node_modules/**/*", "**/*.spec.ts" ] } diff --git a/packages/nodes-base/test/placeholder.test.ts b/packages/nodes-base/test/placeholder.test.ts new file mode 100644 index 0000000000..23ba06a64f --- /dev/null +++ b/packages/nodes-base/test/placeholder.test.ts @@ -0,0 +1,7 @@ +describe('Placeholder', () => { + + test('example', () => { + expect(1 + 1).toEqual(2); + }); + +});