From 03d1244e516d8f0c0ef3f003a8d1107ee911d808 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sat, 14 Dec 2019 22:52:26 +0100 Subject: [PATCH 01/11] chore: publish current build on local registry --- package.json | 3 +- test/e2e-pkg/config/_bootstrap_verdaccio.yaml | 33 +++++++ test/e2e-pkg/env_babel.js | 4 + test/e2e-pkg/jest.config.e2e.pkg.js | 10 ++ test/e2e-pkg/projects/basic/.npmignore | 0 test/e2e-pkg/projects/basic/README.md | 3 + test/e2e-pkg/projects/basic/index.js | 6 ++ test/e2e-pkg/projects/basic/package.json | 18 ++++ test/e2e-pkg/projects/scoped_basic/.npmignore | 0 test/e2e-pkg/projects/scoped_basic/README.md | 3 + test/e2e-pkg/projects/scoped_basic/index.js | 6 ++ .../projects/scoped_basic/package.json | 15 +++ test/e2e-pkg/setup/test_environment.ts | 49 ++++++++++ .../test/publish/publish.private.pkg.spec.ts | 25 +++++ test/e2e-pkg/utils/global.js | 14 +++ test/e2e-pkg/utils/process.js | 88 ++++++++++++++++++ yarn.lock | Bin 373058 -> 376493 bytes 17 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 test/e2e-pkg/config/_bootstrap_verdaccio.yaml create mode 100644 test/e2e-pkg/env_babel.js create mode 100644 test/e2e-pkg/jest.config.e2e.pkg.js create mode 100644 test/e2e-pkg/projects/basic/.npmignore create mode 100644 test/e2e-pkg/projects/basic/README.md create mode 100644 test/e2e-pkg/projects/basic/index.js create mode 100644 test/e2e-pkg/projects/basic/package.json create mode 100644 test/e2e-pkg/projects/scoped_basic/.npmignore create mode 100644 test/e2e-pkg/projects/scoped_basic/README.md create mode 100644 test/e2e-pkg/projects/scoped_basic/index.js create mode 100644 test/e2e-pkg/projects/scoped_basic/package.json create mode 100644 test/e2e-pkg/setup/test_environment.ts create mode 100644 test/e2e-pkg/test/publish/publish.private.pkg.spec.ts create mode 100644 test/e2e-pkg/utils/global.js create mode 100644 test/e2e-pkg/utils/process.js diff --git a/package.json b/package.json index 0e3c1e90f..728a68a91 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,8 @@ "supertest": "4.0.2", "typescript": "3.7.1-rc", "verdaccio-auth-memory": "8.3.0", - "verdaccio-memory": "8.2.0" + "verdaccio-memory": "8.2.0", + "verdaccio": "latest" }, "keywords": [ "private", diff --git a/test/e2e-pkg/config/_bootstrap_verdaccio.yaml b/test/e2e-pkg/config/_bootstrap_verdaccio.yaml new file mode 100644 index 000000000..d699b99c2 --- /dev/null +++ b/test/e2e-pkg/config/_bootstrap_verdaccio.yaml @@ -0,0 +1,33 @@ +storage: ./storage + +auth: + htpasswd: + file: ./htpasswd + max_users: -1 + +web: + enable: true + title: verdaccio-e2e-pkg + +uplinks: + npmjs: + url: https://registry.npmjs.org/ + +logs: + - { type: stdout, format: pretty, level: info } + +packages: + '@*/*': + access: $all + publish: $anonymous + unpublish: $authenticated + proxy: npmjs + 'verdaccio': + access: $authenticated + publish: $anonymous + '**': + access: $all + publish: $anonymous + unpublish: $authenticated + proxy: npmjs +_debug: true diff --git a/test/e2e-pkg/env_babel.js b/test/e2e-pkg/env_babel.js new file mode 100644 index 000000000..eddce9aa3 --- /dev/null +++ b/test/e2e-pkg/env_babel.js @@ -0,0 +1,4 @@ +require('@babel/register')({ + extensions: [".ts", ".js"] +}); +module.exports = require('./setup/test_environment'); diff --git a/test/e2e-pkg/jest.config.e2e.pkg.js b/test/e2e-pkg/jest.config.e2e.pkg.js new file mode 100644 index 000000000..7d9476a00 --- /dev/null +++ b/test/e2e-pkg/jest.config.e2e.pkg.js @@ -0,0 +1,10 @@ +const { defaults } = require('jest-config'); + +module.exports = { + name: 'verdaccio-e2e-pkg-jest', + verbose: true, + collectCoverage: false, + moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts'], + testEnvironment: './env_babel.js', + testRegex: '(/test/e2e.*\\.spec)\\.ts' +}; diff --git a/test/e2e-pkg/projects/basic/.npmignore b/test/e2e-pkg/projects/basic/.npmignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/e2e-pkg/projects/basic/README.md b/test/e2e-pkg/projects/basic/README.md new file mode 100644 index 000000000..80c7d1601 --- /dev/null +++ b/test/e2e-pkg/projects/basic/README.md @@ -0,0 +1,3 @@ +# Simple project + +This is a normal readme diff --git a/test/e2e-pkg/projects/basic/index.js b/test/e2e-pkg/projects/basic/index.js new file mode 100644 index 000000000..474a5966c --- /dev/null +++ b/test/e2e-pkg/projects/basic/index.js @@ -0,0 +1,6 @@ +module.exports = function() { + const message = "this is a basic project"; + console.log(message); + + return message; +}; diff --git a/test/e2e-pkg/projects/basic/package.json b/test/e2e-pkg/projects/basic/package.json new file mode 100644 index 000000000..26eb5c0c7 --- /dev/null +++ b/test/e2e-pkg/projects/basic/package.json @@ -0,0 +1,18 @@ +{ + "name": "basic-verdaccio", + "version": "1.0.0", + "description": "this is a basic project", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "verdaccio", + "sample" + ], + "dependencies": { + "lodash": "^4.17.15" + }, + "author": "Juan Picado ", + "license": "MIT" +} diff --git a/test/e2e-pkg/projects/scoped_basic/.npmignore b/test/e2e-pkg/projects/scoped_basic/.npmignore new file mode 100644 index 000000000..e69de29bb diff --git a/test/e2e-pkg/projects/scoped_basic/README.md b/test/e2e-pkg/projects/scoped_basic/README.md new file mode 100644 index 000000000..80c7d1601 --- /dev/null +++ b/test/e2e-pkg/projects/scoped_basic/README.md @@ -0,0 +1,3 @@ +# Simple project + +This is a normal readme diff --git a/test/e2e-pkg/projects/scoped_basic/index.js b/test/e2e-pkg/projects/scoped_basic/index.js new file mode 100644 index 000000000..76e3f217a --- /dev/null +++ b/test/e2e-pkg/projects/scoped_basic/index.js @@ -0,0 +1,6 @@ +module.exports = function() { + const message = "this is a scoped basic project"; + console.log(message); + + return message; +}; diff --git a/test/e2e-pkg/projects/scoped_basic/package.json b/test/e2e-pkg/projects/scoped_basic/package.json new file mode 100644 index 000000000..add49d051 --- /dev/null +++ b/test/e2e-pkg/projects/scoped_basic/package.json @@ -0,0 +1,15 @@ +{ + "name": "@e2e-verdaccio/basic", + "version": "1.0.0", + "description": "this is a scoped basic project", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": ["verdaccio", "sample", "scoped"], + "dependencies": { + "lodash": "^4.17.15" + }, + "author": "Juan Picado ", + "license": "MIT" +} diff --git a/test/e2e-pkg/setup/test_environment.ts b/test/e2e-pkg/setup/test_environment.ts new file mode 100644 index 000000000..60b8cbea8 --- /dev/null +++ b/test/e2e-pkg/setup/test_environment.ts @@ -0,0 +1,49 @@ +import { yellow } from 'kleur'; +const fs = require('fs'); +import os from 'os'; +import {ChildProcess, spawn} from 'child_process'; +import path from 'path'; +import NodeEnvironment from 'jest-environment-node'; +const __global = require('../utils/global'); +import { npm } from '../utils/process'; + + +class PuppeteerEnvironment extends NodeEnvironment { + private registryProcess: ChildProcess | null; + constructor(config) { + super(config) + this.registryProcess = null; + } + + async setup() { + const tempRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'verdaccio-cli-e2e-')); + __global.addItem('dir-root', tempRoot); + console.log(yellow(`Add temp root folder: ${tempRoot}`)); + fs.copyFileSync( + path.join(__dirname, '../config/_bootstrap_verdaccio.yaml'), + path.join(tempRoot, 'verdaccio.yaml'), + ); + this.global.__namespace = __global; + console.log(`current directory: ${process.cwd()}`); + console.log('resolve-->', require.resolve('verdaccio/bin/verdaccio')); + this.registryProcess = spawn( + 'node', + [require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'], + { cwd: tempRoot, stdio: 'inherit' }, + ); + + // publish current build version on local registry + await npm('publish', '--registry' ,'http://localhost:4873'); + } + + async teardown() { + // @ts-ignore + this.registryProcess.kill() + } + + runScript(script) { + return super.runScript(script); + } +} + +export default PuppeteerEnvironment; diff --git a/test/e2e-pkg/test/publish/publish.private.pkg.spec.ts b/test/e2e-pkg/test/publish/publish.private.pkg.spec.ts new file mode 100644 index 000000000..2c83bcbac --- /dev/null +++ b/test/e2e-pkg/test/publish/publish.private.pkg.spec.ts @@ -0,0 +1,25 @@ +import path from 'path'; +import { npm } from '../../utils/process'; + +function testExample() { + console.log('running example'); + return Promise.resolve(true); +} + +export default async function() { + await testExample(); +} + +describe('test example', ()=> { + + test('sub example', async () => { + console.log(`New directory: ${process.cwd()}`, __dirname); + process.chdir(path.join(__dirname, '../../projects/basic')); + console.log(`New directory: ${process.cwd()}`); + await npm('install', '--registry' ,'http://localhost:4873'); + + // @ts-ignore + console.log('--->', global.__namespace.getItem('dir-root')); + expect(true).toBe(true); + }) +}); diff --git a/test/e2e-pkg/utils/global.js b/test/e2e-pkg/utils/global.js new file mode 100644 index 000000000..fe593662c --- /dev/null +++ b/test/e2e-pkg/utils/global.js @@ -0,0 +1,14 @@ +const namespace = Object.create(null); + +exports.addItem = function(name, value) { + namespace[name] = value; +} + +exports.getItem = function(name) { + console.log("get-item", name, namespace); + if (!(name in namespace)) { + throw new Error("The item ".concat(name, " does exist in the namespace")); + } + + return namespace[name]; +} diff --git a/test/e2e-pkg/utils/process.js b/test/e2e-pkg/utils/process.js new file mode 100644 index 000000000..8f6aee24c --- /dev/null +++ b/test/e2e-pkg/utils/process.js @@ -0,0 +1,88 @@ +import * as child_process from 'child_process'; + +export async function _exec(options, cmd, args) { + let stdout = ''; + let stderr = ''; + const flags = []; + const cwd = process.cwd(); + const env = options.env; + console.log(`Running \`${cmd} ${args.map(x => `"${x}"`).join(' ')}\`${flags}...`); + console.log(`CWD: ${cwd}`); + console.log(`ENV: ${JSON.stringify(env)}`); + const spawnOptions = { + cwd, + ...env ? { env } : {}, + }; + + if (process.platform.startsWith('win')) { + args.unshift('/c', cmd); + cmd = 'cmd.exe'; + spawnOptions['stdio'] = 'pipe'; + } + + + const childProcess = child_process.spawn(cmd, args, spawnOptions); + childProcess.stdout.on('data', (data) => { + stdout += data.toString('utf-8'); + if (options.silent) { + return; + } + data.toString('utf-8') + .split(/[\n\r]+/) + .filter(line => line !== '') + .forEach(line => console.log(' ' + line)); + }); + childProcess.stderr.on('data', (data) => { + stderr += data.toString('utf-8'); + if (options.silent) { + return; + } + data.toString('utf-8') + .split(/[\n\r]+/) + .filter(line => line !== '') + .forEach(line => console.error((' ' + line))); + }); + + // Create the error here so the stack shows who called this function. + const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `); + return new Promise((resolve, reject) => { + childProcess.on('exit', (error) => { + // _processes = _processes.filter(p => p !== childProcess); + + if (!error) { + resolve({ stdout, stderr }); + } else { + err.message += `${error}...\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`; + reject(err); + } + }); + + if (options.waitForMatch) { + const match = options.waitForMatch; + childProcess.stdout.on('data', (data) => { + if (data.toString().match(match)) { + resolve({ stdout, stderr }); + } + }); + childProcess.stderr.on('data', (data) => { + if (data.toString().match(match)) { + resolve({ stdout, stderr }); + } + }); + } + }); +} + + +export function npm(...args) { + return _exec({}, 'npm', args); +} + + +export function node(...args) { + return _exec({}, 'node', args); +} + +export function silentNpm(...args) { + return _exec({silent: true}, 'npm', args); +} diff --git a/yarn.lock b/yarn.lock index adfd65069068e53c5ce4cf5e41d9fd2506b6cf1f..8acb0a9b58341e5da74081c0263861b9df436f54 100644 GIT binary patch delta 1782 zcmZ`(U5Fc16lSs;idCs?b-S%dV=5?Ylg!VZp9rnZ-|kL!limF8ZeHZh%)QAZGn2_= z^0%P1T6bIeRQBQGgNh*Ni-I5o^r^*X1rY_GtkC!NMMRK#v)SERL>Rct`OZD(JKs6y z-u->N?nC^1AB6Lu$i#e`Y}GA_hKot>%}W* z=r6~VfzVlZwv9xtSKCO8Iz6+t5|3@i(yQs3&4T54LUPyRZCJw1&5=>5qBN*&k&`qX$Um&-3gC|J#W-v;S%2dYREisS&Mf-G?Idw!EauTm#Nf2}(VWdb%(L_TOv8F)) zpawb4-~}X*+n+OY6|Aak(=dn7SZfs){l%7F8wi=)Xltoo?()ud!)h(%;u|&G2Zd$c ztyXOh54lXd+evyWtIL)Cpzf_H-89xy%3wKLko<1Gx_9lyJozQdgc+9nMUU|}D)ZxP zfDe-oao`Q|Ajv#Se$6xU3;e#$5(bc$p{5D4!oj!qSs3gp(5wB{$>YfgcQy#CHZn@V6AWDt<8mM zsifC8@{QPNtCaTE)B<1X4C;xcT_?|soqXW@v6CRmzJ5Fu>Lagfww+K|CU^b_aO8(d z;Q1KE_UUQ}1Eixkk~tah0)&{=1yKQ#$N_=XWI=?6Bnf-B<8zyfMjAUCPO91*mdox& zMlhsoy&-1PYC=d2y`j0AaNUY|J~nbHLsM9=^jNC3%#APNF9B&bWQ ztRn!}IH%}X)HTw%F?*)mD2_6?SzKQnl(%wrsUXC#T!}mDN-bZrwU%8$Em>k~?$AlC zZ)DX5gsa6~rPOz`f`n@;sijPQxH=f7tnGoj<~o~soNADJk7mx2$on&Y&TvsMer;!F zhZ$eEKI44(H2uFAat2-Kn&i3PX6DGpg;|#T%*~$Kz0c2%@AJVs)t3yY>t_3k1%1@@ zpXd&V3VZj27Kvg+RNU{DjAR2rAWJ%H01ng2l{haLK&L~c3mnhU z!2=RcIy&73P675PX~U#0J5{&5l}(jbn+=$(E^tO_5Hs3}ZYAtNr9MoFrfsK_7=W$K zY%Jw#*-EkA5e2@qTJ{V}1qckCq9uc3d9ua)l0q4=VLDr(Q25Fb(U{fNp%v-+Z4cH_ zI22Z*lgH^lZXRu+J;BM!&EU(I|HrFmM*Ifa_hV@~ei|oRTFaMw8o>^Qxrr|1O_iA^ zCvFAKUe$We2+}#{qDquI@Ymb64IKk{p)jR<7=>D04|S(&!A0dLm`2yz?UsqUp)gBr z!lBKh2A;+grv?L#n$)tNMV^|F(>I;txJ`E~N;fM^?pzO^JK3O#Eu_K8eLy=XkheaV zJww__=Gc0(8yP{{ny}*NHx1M5ww(de{B{e`GHAj>pk<-nK?Mh_sMIZNS}0L#GfI|^%(=l!6>y4>o2h!Lr z!}Q$A%_CNJe{zpIBrm%&RPU8m-adY5{DE#1h*7C1;JLg5tjv=Czn|s`Tzg` From 73f021c6038385cbdd2445d91fef8d401d854ae9 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sat, 14 Dec 2019 22:58:17 +0100 Subject: [PATCH 02/11] chore: add ci conf for e2e pkg --- .circleci/config.yml | 16 ++++++++++++++++ package.json | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 02f79c2c0..ab0c1db44 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -110,6 +110,14 @@ jobs: - run: name: Test End-to-End command: yarn run test:e2e + test_e2e_cli: + <<: *defaults + executor: node_latest + steps: + - restore_repo + - run: + name: Test End-to-End ClI + command: yarn run test:e2e:pkg coverage: <<: *defaults @@ -149,7 +157,15 @@ workflows: - test_node_lts_10 - test_node_lts_12 <<: *ignore_non_dev_branches + - test_e2e_cli + requires: + - prepare + - test_node_latest + - test_node_lts_10 + - test_node_lts_12 + <<: *ignore_non_dev_branches - coverage: requires: - test_e2e + - test_e2e_cli <<: *ignore_non_dev_branches diff --git a/package.json b/package.json index 728a68a91..069448dac 100644 --- a/package.json +++ b/package.json @@ -117,8 +117,9 @@ "test:clean": "npx jest --clearCache", "test:unit": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC FORCE_COLOR=1 jest --config ./jest.config.js --maxWorkers 2 --passWithNoTests", "test:functional": "cross-env NODE_ENV=test jest --config ./test/jest.config.functional.js --testPathPattern ./test/functional/index* --passWithNoTests", + "test:e2e:pkg": "cross-env NODE_ENV=test jest --config ./test/e2e-pkg/jest.config.e2e.pkg.js --passWithNoTests", "test:e2e": "cross-env BABEL_ENV=test jest --config ./test/jest.config.e2e.js", - "test:all": "npm run test && npm run test:functional && npm run test:e2e", + "test:all": "npm run test && npm run test:functional && npm run test:e2e & npm run test:e2e:pkg", "pre:ci": "npm run lint", "coverage:publish": "codecov", "lint": "npm run type-check && npm run lint:ts && npm run lint:lockfile", From 6fd52203ed9b61c035a6eadbb13f8f8307650dcb Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sat, 14 Dec 2019 22:59:14 +0100 Subject: [PATCH 03/11] chore: typo --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ab0c1db44..0f867832b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -157,7 +157,7 @@ workflows: - test_node_lts_10 - test_node_lts_12 <<: *ignore_non_dev_branches - - test_e2e_cli + - test_e2e_cli: requires: - prepare - test_node_latest From 10ccc4a59f6d7612e73c725e8dec4070eb433796 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sat, 14 Dec 2019 23:00:32 +0100 Subject: [PATCH 04/11] chore: fix tab --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0f867832b..de5147b6c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -163,7 +163,7 @@ workflows: - test_node_latest - test_node_lts_10 - test_node_lts_12 - <<: *ignore_non_dev_branches + <<: *ignore_non_dev_branches - coverage: requires: - test_e2e From 3bf2196388033a026cb1e1e6317d33632c9bea75 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 08:52:55 +0100 Subject: [PATCH 05/11] chore: reorganize setup files --- .circleci/config.yml | 2 +- .eslintrc | 6 +-- package.json | 2 +- test/.eslintrc | 3 +- test/e2e-cli/.eslintrc | 6 +++ .../config/_bootstrap_verdaccio.yaml | 0 test/{e2e-pkg => e2e-cli}/env_babel.js | 0 test/e2e-cli/env_setup.js | 4 ++ test/e2e-cli/env_teardown.js | 4 ++ .../jest.config.e2e.cli.js} | 4 +- .../projects/basic/.npmignore | 0 .../projects/basic/README.md | 0 .../projects/basic/index.js | 0 .../projects/basic/package.json | 1 + .../projects/scoped_basic/.npmignore | 0 .../projects/scoped_basic/README.md | 0 .../projects/scoped_basic/index.js | 0 .../projects/scoped_basic/package.json | 0 test/e2e-cli/setup/setup.ts | 29 +++++++++++ test/e2e-cli/setup/teardown.ts | 4 ++ test/e2e-cli/setup/test_environment.ts | 28 +++++++++++ test/e2e-cli/test/install/install.spec.ts | 29 +++++++++++ .../test/publish/publish.private.pkg.spec.ts | 6 ++- test/{e2e-pkg => e2e-cli}/utils/global.js | 0 test/{e2e-pkg => e2e-cli}/utils/process.js | 0 test/e2e-pkg/setup/test_environment.ts | 49 ------------------- 26 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 test/e2e-cli/.eslintrc rename test/{e2e-pkg => e2e-cli}/config/_bootstrap_verdaccio.yaml (100%) rename test/{e2e-pkg => e2e-cli}/env_babel.js (100%) create mode 100644 test/e2e-cli/env_setup.js create mode 100644 test/e2e-cli/env_teardown.js rename test/{e2e-pkg/jest.config.e2e.pkg.js => e2e-cli/jest.config.e2e.cli.js} (70%) rename test/{e2e-pkg => e2e-cli}/projects/basic/.npmignore (100%) rename test/{e2e-pkg => e2e-cli}/projects/basic/README.md (100%) rename test/{e2e-pkg => e2e-cli}/projects/basic/index.js (100%) rename test/{e2e-pkg => e2e-cli}/projects/basic/package.json (93%) rename test/{e2e-pkg => e2e-cli}/projects/scoped_basic/.npmignore (100%) rename test/{e2e-pkg => e2e-cli}/projects/scoped_basic/README.md (100%) rename test/{e2e-pkg => e2e-cli}/projects/scoped_basic/index.js (100%) rename test/{e2e-pkg => e2e-cli}/projects/scoped_basic/package.json (100%) create mode 100644 test/e2e-cli/setup/setup.ts create mode 100644 test/e2e-cli/setup/teardown.ts create mode 100644 test/e2e-cli/setup/test_environment.ts create mode 100644 test/e2e-cli/test/install/install.spec.ts rename test/{e2e-pkg => e2e-cli}/test/publish/publish.private.pkg.spec.ts (86%) rename test/{e2e-pkg => e2e-cli}/utils/global.js (100%) rename test/{e2e-pkg => e2e-cli}/utils/process.js (100%) delete mode 100644 test/e2e-pkg/setup/test_environment.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index de5147b6c..bc60f04b0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,7 +117,7 @@ jobs: - restore_repo - run: name: Test End-to-End ClI - command: yarn run test:e2e:pkg + command: yarn run test:e2e:cli coverage: <<: *defaults diff --git a/.eslintrc b/.eslintrc index a7443349a..881e7792c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,10 +3,10 @@ "@verdaccio" ], "rules": { - "@typescript-eslint/no-var-requires": ["warn"], + "@typescript-eslint/no-var-requires": 0, "@typescript-eslint/ban-ts-ignore": 0, - "@typescript-eslint/no-inferrable-types": ["warn"], - "@typescript-eslint/no-empty-function": ["warn"], + "@typescript-eslint/no-inferrable-types": 0, + "@typescript-eslint/no-empty-function": 0, "@typescript-eslint/no-this-alias": ["warn"], "@typescript-eslint/no-use-before-define": 0, "@typescript-eslint/array-type": ["warn"], diff --git a/package.json b/package.json index 069448dac..3c0e2e4dc 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "test:clean": "npx jest --clearCache", "test:unit": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC FORCE_COLOR=1 jest --config ./jest.config.js --maxWorkers 2 --passWithNoTests", "test:functional": "cross-env NODE_ENV=test jest --config ./test/jest.config.functional.js --testPathPattern ./test/functional/index* --passWithNoTests", - "test:e2e:pkg": "cross-env NODE_ENV=test jest --config ./test/e2e-pkg/jest.config.e2e.pkg.js --passWithNoTests", + "test:e2e:cli": "cross-env NODE_ENV=test jest --config ./test/e2e-cli/jest.config.e2e.cli.js --passWithNoTests", "test:e2e": "cross-env BABEL_ENV=test jest --config ./test/jest.config.e2e.js", "test:all": "npm run test && npm run test:functional && npm run test:e2e & npm run test:e2e:pkg", "pre:ci": "npm run lint", diff --git a/test/.eslintrc b/test/.eslintrc index d462ff13f..b2c8bc5d2 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -24,6 +24,7 @@ } ], "no-useless-escape": 0, - "@typescript-eslint/explicit-function-return-type": 0 + "@typescript-eslint/explicit-function-return-type": 0, + "@typescript-eslint/no-empty-function": 0 } } diff --git a/test/e2e-cli/.eslintrc b/test/e2e-cli/.eslintrc new file mode 100644 index 000000000..cbfb89d2f --- /dev/null +++ b/test/e2e-cli/.eslintrc @@ -0,0 +1,6 @@ +{ + "rules": { + "@typescript-eslint/no-var-requires": 0, + "@typescript-eslint/explicit-member-accessibility": 0 + } +} diff --git a/test/e2e-pkg/config/_bootstrap_verdaccio.yaml b/test/e2e-cli/config/_bootstrap_verdaccio.yaml similarity index 100% rename from test/e2e-pkg/config/_bootstrap_verdaccio.yaml rename to test/e2e-cli/config/_bootstrap_verdaccio.yaml diff --git a/test/e2e-pkg/env_babel.js b/test/e2e-cli/env_babel.js similarity index 100% rename from test/e2e-pkg/env_babel.js rename to test/e2e-cli/env_babel.js diff --git a/test/e2e-cli/env_setup.js b/test/e2e-cli/env_setup.js new file mode 100644 index 000000000..222f7183e --- /dev/null +++ b/test/e2e-cli/env_setup.js @@ -0,0 +1,4 @@ +require('@babel/register')({ + extensions: [".ts", ".js"] +}); +module.exports = require('./setup/setup'); diff --git a/test/e2e-cli/env_teardown.js b/test/e2e-cli/env_teardown.js new file mode 100644 index 000000000..75165a7c7 --- /dev/null +++ b/test/e2e-cli/env_teardown.js @@ -0,0 +1,4 @@ +require('@babel/register')({ + extensions: [".ts", ".js"] +}); +module.exports = require('./setup/teardown'); diff --git a/test/e2e-pkg/jest.config.e2e.pkg.js b/test/e2e-cli/jest.config.e2e.cli.js similarity index 70% rename from test/e2e-pkg/jest.config.e2e.pkg.js rename to test/e2e-cli/jest.config.e2e.cli.js index 7d9476a00..5cec14386 100644 --- a/test/e2e-pkg/jest.config.e2e.pkg.js +++ b/test/e2e-cli/jest.config.e2e.cli.js @@ -1,10 +1,12 @@ const { defaults } = require('jest-config'); module.exports = { - name: 'verdaccio-e2e-pkg-jest', + name: 'verdaccio-e2e-cli-jest', verbose: true, collectCoverage: false, moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts'], testEnvironment: './env_babel.js', + globalSetup: './env_setup.js', + globalTeardown: './env_teardown.js', testRegex: '(/test/e2e.*\\.spec)\\.ts' }; diff --git a/test/e2e-pkg/projects/basic/.npmignore b/test/e2e-cli/projects/basic/.npmignore similarity index 100% rename from test/e2e-pkg/projects/basic/.npmignore rename to test/e2e-cli/projects/basic/.npmignore diff --git a/test/e2e-pkg/projects/basic/README.md b/test/e2e-cli/projects/basic/README.md similarity index 100% rename from test/e2e-pkg/projects/basic/README.md rename to test/e2e-cli/projects/basic/README.md diff --git a/test/e2e-pkg/projects/basic/index.js b/test/e2e-cli/projects/basic/index.js similarity index 100% rename from test/e2e-pkg/projects/basic/index.js rename to test/e2e-cli/projects/basic/index.js diff --git a/test/e2e-pkg/projects/basic/package.json b/test/e2e-cli/projects/basic/package.json similarity index 93% rename from test/e2e-pkg/projects/basic/package.json rename to test/e2e-cli/projects/basic/package.json index 26eb5c0c7..7f1dec508 100644 --- a/test/e2e-pkg/projects/basic/package.json +++ b/test/e2e-cli/projects/basic/package.json @@ -11,6 +11,7 @@ "sample" ], "dependencies": { + "jquery": "^3.4.1", "lodash": "^4.17.15" }, "author": "Juan Picado ", diff --git a/test/e2e-pkg/projects/scoped_basic/.npmignore b/test/e2e-cli/projects/scoped_basic/.npmignore similarity index 100% rename from test/e2e-pkg/projects/scoped_basic/.npmignore rename to test/e2e-cli/projects/scoped_basic/.npmignore diff --git a/test/e2e-pkg/projects/scoped_basic/README.md b/test/e2e-cli/projects/scoped_basic/README.md similarity index 100% rename from test/e2e-pkg/projects/scoped_basic/README.md rename to test/e2e-cli/projects/scoped_basic/README.md diff --git a/test/e2e-pkg/projects/scoped_basic/index.js b/test/e2e-cli/projects/scoped_basic/index.js similarity index 100% rename from test/e2e-pkg/projects/scoped_basic/index.js rename to test/e2e-cli/projects/scoped_basic/index.js diff --git a/test/e2e-pkg/projects/scoped_basic/package.json b/test/e2e-cli/projects/scoped_basic/package.json similarity index 100% rename from test/e2e-pkg/projects/scoped_basic/package.json rename to test/e2e-cli/projects/scoped_basic/package.json diff --git a/test/e2e-cli/setup/setup.ts b/test/e2e-cli/setup/setup.ts new file mode 100644 index 000000000..3f60036ab --- /dev/null +++ b/test/e2e-cli/setup/setup.ts @@ -0,0 +1,29 @@ +import fs from "fs"; +import path from "path"; +import os from "os"; +import {yellow} from "kleur"; +import {spawn} from "child_process"; +import { npm } from '../utils/process'; +import * as __global from '../utils/global.js'; + +module.exports = async () => { + const tempRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'verdaccio-cli-e2e-')); + __global.addItem('dir-root', tempRoot); + console.log(yellow(`Add temp root folder: ${tempRoot}`)); + fs.copyFileSync( + path.join(__dirname, '../config/_bootstrap_verdaccio.yaml'), + path.join(tempRoot, 'verdaccio.yaml'), + ); + // @ts-ignore + global.__namespace = __global; + console.log(`current directory: ${process.cwd()}`); + // @ts-ignore + global.registryProcess = spawn( + 'node', + [require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'], + { cwd: tempRoot, stdio: 'inherit' }, + ); + + // publish current build version on local registry + await npm('publish', '--registry' ,'http://localhost:4873'); +} diff --git a/test/e2e-cli/setup/teardown.ts b/test/e2e-cli/setup/teardown.ts new file mode 100644 index 000000000..346c5c595 --- /dev/null +++ b/test/e2e-cli/setup/teardown.ts @@ -0,0 +1,4 @@ +module.exports = async function() { + // @ts-ignore + global.registryProcess.kill(); +}; diff --git a/test/e2e-cli/setup/test_environment.ts b/test/e2e-cli/setup/test_environment.ts new file mode 100644 index 000000000..17efe02da --- /dev/null +++ b/test/e2e-cli/setup/test_environment.ts @@ -0,0 +1,28 @@ +const fs = require('fs'); +import os from 'os'; +import path from 'path'; +import NodeEnvironment from 'jest-environment-node'; +const __global = require('../utils/global'); +// import { npm } from '../utils/process'; + + +class PuppeteerEnvironment extends NodeEnvironment { + constructor(config) { + super(config) + } + + async setup() { + const tempRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'verdaccio-suite-test-')); + __global.addItem('dir-root', tempRoot); + this.global.__namespace = __global; + console.log(`current directory: ${process.cwd()}`); + } + + async teardown() {} + + runScript(script) { + return super.runScript(script); + } +} + +export default PuppeteerEnvironment; diff --git a/test/e2e-cli/test/install/install.spec.ts b/test/e2e-cli/test/install/install.spec.ts new file mode 100644 index 000000000..47e0ff28e --- /dev/null +++ b/test/e2e-cli/test/install/install.spec.ts @@ -0,0 +1,29 @@ +import path from 'path'; +import { npm } from '../../utils/process'; + +function testExample() { + console.log('running example'); + return Promise.resolve(true); +} + +export default async function() { + await testExample(); +} + +describe('npm install', ()=> { + + beforeAll(() => { + + }); + + test('should install jquery', async () => { + console.log(`New directory: ${process.cwd()}`, __dirname); + process.chdir(path.join(__dirname, '../../projects/basic')); + console.log(`New directory: ${process.cwd()}`); + await npm('install', 'jquery', '--registry' ,'http://localhost:4873'); + + // @ts-ignore + // console.log('--->', global.__namespace.getItem('dir-root')); + expect(true).toBe(true); + }) +}); diff --git a/test/e2e-pkg/test/publish/publish.private.pkg.spec.ts b/test/e2e-cli/test/publish/publish.private.pkg.spec.ts similarity index 86% rename from test/e2e-pkg/test/publish/publish.private.pkg.spec.ts rename to test/e2e-cli/test/publish/publish.private.pkg.spec.ts index 2c83bcbac..58611d442 100644 --- a/test/e2e-pkg/test/publish/publish.private.pkg.spec.ts +++ b/test/e2e-cli/test/publish/publish.private.pkg.spec.ts @@ -12,6 +12,10 @@ export default async function() { describe('test example', ()=> { + beforeAll(() => { + + }); + test('sub example', async () => { console.log(`New directory: ${process.cwd()}`, __dirname); process.chdir(path.join(__dirname, '../../projects/basic')); @@ -19,7 +23,7 @@ describe('test example', ()=> { await npm('install', '--registry' ,'http://localhost:4873'); // @ts-ignore - console.log('--->', global.__namespace.getItem('dir-root')); + // console.log('--->', global.__namespace.getItem('dir-root')); expect(true).toBe(true); }) }); diff --git a/test/e2e-pkg/utils/global.js b/test/e2e-cli/utils/global.js similarity index 100% rename from test/e2e-pkg/utils/global.js rename to test/e2e-cli/utils/global.js diff --git a/test/e2e-pkg/utils/process.js b/test/e2e-cli/utils/process.js similarity index 100% rename from test/e2e-pkg/utils/process.js rename to test/e2e-cli/utils/process.js diff --git a/test/e2e-pkg/setup/test_environment.ts b/test/e2e-pkg/setup/test_environment.ts deleted file mode 100644 index 60b8cbea8..000000000 --- a/test/e2e-pkg/setup/test_environment.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { yellow } from 'kleur'; -const fs = require('fs'); -import os from 'os'; -import {ChildProcess, spawn} from 'child_process'; -import path from 'path'; -import NodeEnvironment from 'jest-environment-node'; -const __global = require('../utils/global'); -import { npm } from '../utils/process'; - - -class PuppeteerEnvironment extends NodeEnvironment { - private registryProcess: ChildProcess | null; - constructor(config) { - super(config) - this.registryProcess = null; - } - - async setup() { - const tempRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'verdaccio-cli-e2e-')); - __global.addItem('dir-root', tempRoot); - console.log(yellow(`Add temp root folder: ${tempRoot}`)); - fs.copyFileSync( - path.join(__dirname, '../config/_bootstrap_verdaccio.yaml'), - path.join(tempRoot, 'verdaccio.yaml'), - ); - this.global.__namespace = __global; - console.log(`current directory: ${process.cwd()}`); - console.log('resolve-->', require.resolve('verdaccio/bin/verdaccio')); - this.registryProcess = spawn( - 'node', - [require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'], - { cwd: tempRoot, stdio: 'inherit' }, - ); - - // publish current build version on local registry - await npm('publish', '--registry' ,'http://localhost:4873'); - } - - async teardown() { - // @ts-ignore - this.registryProcess.kill() - } - - runScript(script) { - return super.runScript(script); - } -} - -export default PuppeteerEnvironment; From e1685d205ba7d04b03f037ddc744cc3c20ade25b Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 12:07:29 +0100 Subject: [PATCH 06/11] chore: consume previous registry installed --- package.json | 5 ++- test/e2e-cli/config/_bootstrap_verdaccio.yaml | 8 +++- test/e2e-cli/config/default.yaml | 35 ++++++++++++++++++ test/e2e-cli/projects/basic/package.json | 3 +- .../projects/scoped_basic/package.json | 2 +- test/e2e-cli/test/install/install.spec.ts | 35 ++++++++++++++---- .../test/publish/publish.private.pkg.spec.ts | 10 ++--- test/e2e-cli/utils/process.js | 1 + test/e2e-cli/utils/registry.ts | 26 +++++++++++++ yarn.lock | Bin 376493 -> 377645 bytes 10 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 test/e2e-cli/config/default.yaml create mode 100644 test/e2e-cli/utils/registry.ts diff --git a/package.json b/package.json index 3c0e2e4dc..844f1859c 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "cross-env": "6.0.3", "detect-secrets": "1.0.5", "eslint": "5.16.0", + "fs-extra": "8.1.0", "get-stdin": "7.0.0", "husky": "2.7.0", "in-publish": "2.0.0", @@ -92,9 +93,9 @@ "standard-version": "7.0.0", "supertest": "4.0.2", "typescript": "3.7.1-rc", + "verdaccio": "latest", "verdaccio-auth-memory": "8.3.0", - "verdaccio-memory": "8.2.0", - "verdaccio": "latest" + "verdaccio-memory": "8.2.0" }, "keywords": [ "private", diff --git a/test/e2e-cli/config/_bootstrap_verdaccio.yaml b/test/e2e-cli/config/_bootstrap_verdaccio.yaml index d699b99c2..50fe65d73 100644 --- a/test/e2e-cli/config/_bootstrap_verdaccio.yaml +++ b/test/e2e-cli/config/_bootstrap_verdaccio.yaml @@ -1,5 +1,9 @@ storage: ./storage +#store: +# memory: +# limit: 1000 + auth: htpasswd: file: ./htpasswd @@ -14,7 +18,7 @@ uplinks: url: https://registry.npmjs.org/ logs: - - { type: stdout, format: pretty, level: info } + - { type: stdout, format: pretty, level: warn } packages: '@*/*': @@ -23,7 +27,7 @@ packages: unpublish: $authenticated proxy: npmjs 'verdaccio': - access: $authenticated + access: $all publish: $anonymous '**': access: $all diff --git a/test/e2e-cli/config/default.yaml b/test/e2e-cli/config/default.yaml new file mode 100644 index 000000000..ae05e1af1 --- /dev/null +++ b/test/e2e-cli/config/default.yaml @@ -0,0 +1,35 @@ +storage: ./storage + +#store: +# memory: +# limit: 1000 + +auth: + htpasswd: + file: ./htpasswd + max_users: -1 + +web: + enable: true + title: verdaccio-default + +uplinks: + npmjs: + url: http://localhost:4873 + +logs: + - { type: stdout, format: pretty, level: info } + +packages: + '@*/*': + access: $all + publish: $anonymous + unpublish: $authenticated + proxy: npmjs + '**': + access: $all + publish: $all + unpublish: $authenticated + proxy: npmjs + +_debug: true diff --git a/test/e2e-cli/projects/basic/package.json b/test/e2e-cli/projects/basic/package.json index 7f1dec508..59afd2e21 100644 --- a/test/e2e-cli/projects/basic/package.json +++ b/test/e2e-cli/projects/basic/package.json @@ -11,8 +11,7 @@ "sample" ], "dependencies": { - "jquery": "^3.4.1", - "lodash": "^4.17.15" + "verdaccio": "latest" }, "author": "Juan Picado ", "license": "MIT" diff --git a/test/e2e-cli/projects/scoped_basic/package.json b/test/e2e-cli/projects/scoped_basic/package.json index add49d051..bfa5b01de 100644 --- a/test/e2e-cli/projects/scoped_basic/package.json +++ b/test/e2e-cli/projects/scoped_basic/package.json @@ -8,7 +8,7 @@ }, "keywords": ["verdaccio", "sample", "scoped"], "dependencies": { - "lodash": "^4.17.15" + "verdaccio": "latest" }, "author": "Juan Picado ", "license": "MIT" diff --git a/test/e2e-cli/test/install/install.spec.ts b/test/e2e-cli/test/install/install.spec.ts index 47e0ff28e..9f9109d74 100644 --- a/test/e2e-cli/test/install/install.spec.ts +++ b/test/e2e-cli/test/install/install.spec.ts @@ -1,5 +1,8 @@ import path from 'path'; import { npm } from '../../utils/process'; +import fs from "fs"; +import * as __global from "../../utils/global"; +import {spawnRegistry} from "../../utils/registry"; function testExample() { console.log('running example'); @@ -11,19 +14,35 @@ export default async function() { } describe('npm install', ()=> { + jest.setTimeout(90000); - beforeAll(() => { + // @ts-ignore + const tempRootFolder = global.__namespace.getItem('dir-root'); + let registryProcess; + + beforeAll(async () => { + const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root'); + await npm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock'); + const configPath = path.join(tempRootFolder, 'verdaccio.yaml'); + fs.copyFileSync(path.join(__dirname, '../../config/default.yaml'), configPath); + // @ts-ignore + global.__namespace = __global; + const pathVerdaccioModule = require.resolve('verdaccio/bin/verdaccio', { + paths: [verdaccioInstall] + }); + registryProcess = await spawnRegistry(pathVerdaccioModule, + ['-c', configPath, '-l', '9011'], + { cwd: verdaccioInstall, silent: false } + ); }); test('should install jquery', async () => { - console.log(`New directory: ${process.cwd()}`, __dirname); - process.chdir(path.join(__dirname, '../../projects/basic')); - console.log(`New directory: ${process.cwd()}`); - await npm('install', 'jquery', '--registry' ,'http://localhost:4873'); - - // @ts-ignore - // console.log('--->', global.__namespace.getItem('dir-root')); + await npm('info', 'verdaccio', '--registry' ,'http://localhost:9011'); expect(true).toBe(true); }) + + afterAll(async () => { + registryProcess.kill(); + }); }); diff --git a/test/e2e-cli/test/publish/publish.private.pkg.spec.ts b/test/e2e-cli/test/publish/publish.private.pkg.spec.ts index 58611d442..4aae6fc79 100644 --- a/test/e2e-cli/test/publish/publish.private.pkg.spec.ts +++ b/test/e2e-cli/test/publish/publish.private.pkg.spec.ts @@ -1,5 +1,5 @@ import path from 'path'; -import { npm } from '../../utils/process'; +// import { npm } from '../../utils/process'; function testExample() { console.log('running example'); @@ -10,18 +10,18 @@ export default async function() { await testExample(); } -describe('test example', ()=> { +describe.skip('test example', ()=> { beforeAll(() => { }); - test('sub example', async () => { + test('sub example', async (done) => { console.log(`New directory: ${process.cwd()}`, __dirname); process.chdir(path.join(__dirname, '../../projects/basic')); console.log(`New directory: ${process.cwd()}`); - await npm('install', '--registry' ,'http://localhost:4873'); - + // await npm('install', '--registry' ,'http://localhost:4873'); + done(); // @ts-ignore // console.log('--->', global.__namespace.getItem('dir-root')); expect(true).toBe(true); diff --git a/test/e2e-cli/utils/process.js b/test/e2e-cli/utils/process.js index 8f6aee24c..581a56375 100644 --- a/test/e2e-cli/utils/process.js +++ b/test/e2e-cli/utils/process.js @@ -48,6 +48,7 @@ export async function _exec(options, cmd, args) { return new Promise((resolve, reject) => { childProcess.on('exit', (error) => { // _processes = _processes.filter(p => p !== childProcess); + console.log("--EXIT PROCESS-->", error); if (!error) { resolve({ stdout, stderr }); diff --git a/test/e2e-cli/utils/registry.ts b/test/e2e-cli/utils/registry.ts new file mode 100644 index 000000000..6595ce546 --- /dev/null +++ b/test/e2e-cli/utils/registry.ts @@ -0,0 +1,26 @@ +import {fork} from "child_process"; + +export function prepareEnvironment(rootFolder: string, folderName: string) { + +} + +export function spawnRegistry( + verdaccioPath: string, + args: string[], + childOptions) { + return new Promise((resolve, reject) => { + let _childOptions = {silent: true, ...childOptions}; + + const childFork = fork(verdaccioPath, args, _childOptions); + + childFork.on('message', (msg) => { + if ('verdaccio_started' in msg) { + resolve(childFork); + } + }); + + childFork.on('error', (err) => reject([err])); + childFork.on('disconnect', (err) => reject([err])); + childFork.on('exit', (err) => reject([err])); + }); +} diff --git a/yarn.lock b/yarn.lock index 8acb0a9b58341e5da74081c0263861b9df436f54..8d16ca87055cfc9de6a2406ac0c27e15bf2c4383 100644 GIT binary patch delta 783 zcmY+BOKTHR6vs)@E~+R#umVJsWEq%)`^ z%uK4wlxJ}Nkusw>^;W(X#qCZut!1)SK}%S*G|k5b8=1N>lI>PCDW=rCSzwi_gK&0x z*{Fo74FcLWO;a?*>8nSYrz|b9KIE-_5Rbm#kal1C%+rr zPH+ynpEHxt{qV(qJuLiTKp=0LP{%-!yqkd{W8UC_A}~r7APc;#Ga2#j2 z*J4dn>^qLoUQIi8yi~{^-T&(U_{x3rK9F{Ip9Ut>69Qghr!c}}6l1rtBtb$LkQ7D7 z2uN7>GDE;L2oPmcF(6=qzzp5>G2i8@bs@QhQf<8&r9Ilt=bTz8*HPomoMp|szt#iS zJouM<_@QYCRTJN zD2S&-H<)246k|a#WI#PrA~OlW`xoC%mwRfOEs3#mwAFUtW-)}JR8o~R7BpNo$S9Rc z@Fq|7bYqChqfIRV3adg@Z-PW}DI1Fph?tAeNK(yKNHms*+aW+k+D2`D{^;k<Z8<^t8Zhs~e^x6Pmgr{A}Ofd#5TnyC}u From 582b19d02f1fff0fe1d3086d4b9cd61578a69cf5 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 17:06:28 +0100 Subject: [PATCH 07/11] test: add test for install a package --- test/e2e-cli/config/default.yaml | 2 +- test/e2e-cli/test/__partials/npm_commands.ts | 5 +++ test/e2e-cli/test/install/install.spec.ts | 31 ++++++++++++++----- .../test/publish/publish.private.pkg.spec.ts | 29 ----------------- test/e2e-cli/utils/expect.ts | 13 ++++++++ test/e2e-cli/utils/{process.js => process.ts} | 19 ++++++------ test/e2e-cli/utils/utils.ts | 9 ++++++ 7 files changed, 61 insertions(+), 47 deletions(-) create mode 100644 test/e2e-cli/test/__partials/npm_commands.ts delete mode 100644 test/e2e-cli/test/publish/publish.private.pkg.spec.ts create mode 100644 test/e2e-cli/utils/expect.ts rename test/e2e-cli/utils/{process.js => process.ts} (87%) create mode 100644 test/e2e-cli/utils/utils.ts diff --git a/test/e2e-cli/config/default.yaml b/test/e2e-cli/config/default.yaml index ae05e1af1..39ec46bc4 100644 --- a/test/e2e-cli/config/default.yaml +++ b/test/e2e-cli/config/default.yaml @@ -18,7 +18,7 @@ uplinks: url: http://localhost:4873 logs: - - { type: stdout, format: pretty, level: info } + - { type: stdout, format: pretty, level: warn } packages: '@*/*': diff --git a/test/e2e-cli/test/__partials/npm_commands.ts b/test/e2e-cli/test/__partials/npm_commands.ts new file mode 100644 index 000000000..104137f62 --- /dev/null +++ b/test/e2e-cli/test/__partials/npm_commands.ts @@ -0,0 +1,5 @@ +import { npm } from '../../utils/process'; + +export function installVerdaccio(verdaccioInstall) { + return npm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock'); +} diff --git a/test/e2e-cli/test/install/install.spec.ts b/test/e2e-cli/test/install/install.spec.ts index 9f9109d74..9e949af6c 100644 --- a/test/e2e-cli/test/install/install.spec.ts +++ b/test/e2e-cli/test/install/install.spec.ts @@ -1,8 +1,10 @@ import path from 'path'; -import { npm } from '../../utils/process'; import fs from "fs"; import * as __global from "../../utils/global"; import {spawnRegistry} from "../../utils/registry"; +import {execAndWaitForOutputToMatch} from '../../utils/process'; +import {installVerdaccio} from "../__partials/npm_commands"; +import {expectFileToExist} from "../../utils/expect"; function testExample() { console.log('running example'); @@ -15,15 +17,16 @@ export default async function() { describe('npm install', ()=> { jest.setTimeout(90000); + const port = '9011'; // @ts-ignore const tempRootFolder = global.__namespace.getItem('dir-root'); + const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root-install'); let registryProcess; - beforeAll(async () => { - const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root'); - await npm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock'); + await installVerdaccio(verdaccioInstall); + const configPath = path.join(tempRootFolder, 'verdaccio.yaml'); fs.copyFileSync(path.join(__dirname, '../../config/default.yaml'), configPath); // @ts-ignore @@ -32,15 +35,27 @@ describe('npm install', ()=> { paths: [verdaccioInstall] }); registryProcess = await spawnRegistry(pathVerdaccioModule, - ['-c', configPath, '-l', '9011'], + ['-c', configPath, '-l', port], { cwd: verdaccioInstall, silent: false } ); }); + test('should match on npm info verdaccio', async () => { + // FIXME: not the best match, looking for a better way to match the terminal output + const output = await execAndWaitForOutputToMatch('npm', ['info', 'verdaccio', '--registry' ,`http://localhost:${port}`], /verdaccio-4.3.5.tgz/); + + expect(output.ok).toBeTruthy(); + }); + test('should install jquery', async () => { - await npm('info', 'verdaccio', '--registry' ,'http://localhost:9011'); - expect(true).toBe(true); - }) + const testCwd = path.join(tempRootFolder, '_jquery_'); + await execAndWaitForOutputToMatch('npm', ['install', '--prefix', testCwd, 'jquery', '--registry' ,`http://localhost:${port}`], /''/, { + cwd: verdaccioInstall + }); + + const exist = await expectFileToExist(path.join(testCwd, 'node_modules', 'jquery', 'package.json')); + expect(exist).toBeTruthy(); + }); afterAll(async () => { registryProcess.kill(); diff --git a/test/e2e-cli/test/publish/publish.private.pkg.spec.ts b/test/e2e-cli/test/publish/publish.private.pkg.spec.ts deleted file mode 100644 index 4aae6fc79..000000000 --- a/test/e2e-cli/test/publish/publish.private.pkg.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import path from 'path'; -// import { npm } from '../../utils/process'; - -function testExample() { - console.log('running example'); - return Promise.resolve(true); -} - -export default async function() { - await testExample(); -} - -describe.skip('test example', ()=> { - - beforeAll(() => { - - }); - - test('sub example', async (done) => { - console.log(`New directory: ${process.cwd()}`, __dirname); - process.chdir(path.join(__dirname, '../../projects/basic')); - console.log(`New directory: ${process.cwd()}`); - // await npm('install', '--registry' ,'http://localhost:4873'); - done(); - // @ts-ignore - // console.log('--->', global.__namespace.getItem('dir-root')); - expect(true).toBe(true); - }) -}); diff --git a/test/e2e-cli/utils/expect.ts b/test/e2e-cli/utils/expect.ts new file mode 100644 index 000000000..e768caaba --- /dev/null +++ b/test/e2e-cli/utils/expect.ts @@ -0,0 +1,13 @@ +import * as fs from 'fs-extra'; + +export function expectFileToExist(fileName: string) { + return new Promise((resolve, reject) => { + fs.exists(fileName, (exist) => { + if (exist) { + resolve(exist); + } else { + reject(new Error(`File ${fileName} was expected to exist but not found...`)); + } + }); + }); +} diff --git a/test/e2e-cli/utils/process.js b/test/e2e-cli/utils/process.ts similarity index 87% rename from test/e2e-cli/utils/process.js rename to test/e2e-cli/utils/process.ts index 581a56375..6b4d07377 100644 --- a/test/e2e-cli/utils/process.js +++ b/test/e2e-cli/utils/process.ts @@ -1,4 +1,5 @@ import * as child_process from 'child_process'; +import {SpawnOptions} from "child_process"; export async function _exec(options, cmd, args) { let stdout = ''; @@ -47,9 +48,6 @@ export async function _exec(options, cmd, args) { const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `); return new Promise((resolve, reject) => { childProcess.on('exit', (error) => { - // _processes = _processes.filter(p => p !== childProcess); - console.log("--EXIT PROCESS-->", error); - if (!error) { resolve({ stdout, stderr }); } else { @@ -62,7 +60,7 @@ export async function _exec(options, cmd, args) { const match = options.waitForMatch; childProcess.stdout.on('data', (data) => { if (data.toString().match(match)) { - resolve({ stdout, stderr }); + resolve({ok: true, stdout, stderr }); } }); childProcess.stderr.on('data', (data) => { @@ -74,16 +72,19 @@ export async function _exec(options, cmd, args) { }); } +export function execAndWaitForOutputToMatch( + cmd: string, + args: string[], + match: RegExp, + spawnOptions: SpawnOptions = {}): any { + return _exec({ waitForMatch: match, ...spawnOptions }, cmd, args); +} + export function npm(...args) { return _exec({}, 'npm', args); } - -export function node(...args) { - return _exec({}, 'node', args); -} - export function silentNpm(...args) { return _exec({silent: true}, 'npm', args); } diff --git a/test/e2e-cli/utils/utils.ts b/test/e2e-cli/utils/utils.ts new file mode 100644 index 000000000..6cc37b111 --- /dev/null +++ b/test/e2e-cli/utils/utils.ts @@ -0,0 +1,9 @@ +import path from "path"; +import fs from "fs"; + +export function copyConfigFile(rootFolder, configTemplate): string { + const configPath = path.join(rootFolder, 'verdaccio.yaml'); + fs.copyFileSync(path.join(__dirname, configTemplate), configPath); + + return configPath; +} From f5c3b796f2c605768b1b7d6a2c99609b9a42dfb9 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 17:18:40 +0100 Subject: [PATCH 08/11] chore: rename class --- test/e2e-cli/env_babel.js | 2 +- test/e2e-cli/setup/test_environment.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e-cli/env_babel.js b/test/e2e-cli/env_babel.js index eddce9aa3..3503870dd 100644 --- a/test/e2e-cli/env_babel.js +++ b/test/e2e-cli/env_babel.js @@ -1,4 +1,4 @@ require('@babel/register')({ extensions: [".ts", ".js"] }); -module.exports = require('./setup/test_environment'); +module.E2ECliTestEnvironment = require('./setup/test_environment'); diff --git a/test/e2e-cli/setup/test_environment.ts b/test/e2e-cli/setup/test_environment.ts index 17efe02da..4ad640234 100644 --- a/test/e2e-cli/setup/test_environment.ts +++ b/test/e2e-cli/setup/test_environment.ts @@ -6,7 +6,7 @@ const __global = require('../utils/global'); // import { npm } from '../utils/process'; -class PuppeteerEnvironment extends NodeEnvironment { +class E2ECliTestEnvironment extends NodeEnvironment { constructor(config) { super(config) } @@ -25,4 +25,4 @@ class PuppeteerEnvironment extends NodeEnvironment { } } -export default PuppeteerEnvironment; +export default E2ECliTestEnvironment; From 291c8cadc84f3eb8d42250dac83da2a46bec895b Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 17:33:15 +0100 Subject: [PATCH 09/11] chore: fix typo --- test/e2e-cli/env_babel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e-cli/env_babel.js b/test/e2e-cli/env_babel.js index 3503870dd..eddce9aa3 100644 --- a/test/e2e-cli/env_babel.js +++ b/test/e2e-cli/env_babel.js @@ -1,4 +1,4 @@ require('@babel/register')({ extensions: [".ts", ".js"] }); -module.E2ECliTestEnvironment = require('./setup/test_environment'); +module.exports = require('./setup/test_environment'); From b6d2b2690aa265e74adc71b631d784a68731b1d2 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 22:18:47 +0100 Subject: [PATCH 10/11] chore: add info test --- test/e2e-cli/setup/setup.ts | 3 +- test/e2e-cli/test/__partials/npm_commands.ts | 4 +-- test/e2e-cli/test/core/info.spec.ts | 29 ++++++++++++++++++++ test/e2e-cli/test/install/install.spec.ts | 13 ++------- test/e2e-cli/utils/process.ts | 11 ++++++-- 5 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 test/e2e-cli/test/core/info.spec.ts diff --git a/test/e2e-cli/setup/setup.ts b/test/e2e-cli/setup/setup.ts index 3f60036ab..27ac7b771 100644 --- a/test/e2e-cli/setup/setup.ts +++ b/test/e2e-cli/setup/setup.ts @@ -21,7 +21,8 @@ module.exports = async () => { global.registryProcess = spawn( 'node', [require.resolve('verdaccio/bin/verdaccio'), '-c', './verdaccio.yaml'], - { cwd: tempRoot, stdio: 'inherit' }, + // @ts-ignore + { cwd: tempRoot, silence: true }, ); // publish current build version on local registry diff --git a/test/e2e-cli/test/__partials/npm_commands.ts b/test/e2e-cli/test/__partials/npm_commands.ts index 104137f62..9f5515ce4 100644 --- a/test/e2e-cli/test/__partials/npm_commands.ts +++ b/test/e2e-cli/test/__partials/npm_commands.ts @@ -1,5 +1,5 @@ -import { npm } from '../../utils/process'; +import { silentNpm } from '../../utils/process'; export function installVerdaccio(verdaccioInstall) { - return npm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock'); + return silentNpm('install', '--prefix', verdaccioInstall, 'verdaccio', '--registry' ,'http://localhost:4873', '--no-package-lock'); } diff --git a/test/e2e-cli/test/core/info.spec.ts b/test/e2e-cli/test/core/info.spec.ts new file mode 100644 index 000000000..d5fa8047a --- /dev/null +++ b/test/e2e-cli/test/core/info.spec.ts @@ -0,0 +1,29 @@ +import path from 'path'; +import {runVerdaccio} from '../../utils/process'; +import {installVerdaccio} from "../__partials/npm_commands"; + +describe('verdaccio info', ()=> { + jest.setTimeout(90000); + // @ts-ignore + const tempRootFolder = global.__namespace.getItem('dir-root'); + const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root-info'); + let registryProcess; + + beforeAll(async () => { + await installVerdaccio(verdaccioInstall); + }); + + + test('should run verdaccio info command', async () => { + const pathVerdaccioModule = require.resolve('verdaccio/bin/verdaccio', { + paths: [verdaccioInstall] + }); + const hasMatch = await runVerdaccio(pathVerdaccioModule, verdaccioInstall, ['--info'], /Environment/); + + expect(hasMatch.ok).toBeTruthy(); + }); + + afterAll(() => { + registryProcess.kill(); + }); +}); diff --git a/test/e2e-cli/test/install/install.spec.ts b/test/e2e-cli/test/install/install.spec.ts index 9e949af6c..72da34c68 100644 --- a/test/e2e-cli/test/install/install.spec.ts +++ b/test/e2e-cli/test/install/install.spec.ts @@ -6,15 +6,6 @@ import {execAndWaitForOutputToMatch} from '../../utils/process'; import {installVerdaccio} from "../__partials/npm_commands"; import {expectFileToExist} from "../../utils/expect"; -function testExample() { - console.log('running example'); - return Promise.resolve(true); -} - -export default async function() { - await testExample(); -} - describe('npm install', ()=> { jest.setTimeout(90000); const port = '9011'; @@ -36,13 +27,13 @@ describe('npm install', ()=> { }); registryProcess = await spawnRegistry(pathVerdaccioModule, ['-c', configPath, '-l', port], - { cwd: verdaccioInstall, silent: false } + { cwd: verdaccioInstall, silent: true } ); }); test('should match on npm info verdaccio', async () => { // FIXME: not the best match, looking for a better way to match the terminal output - const output = await execAndWaitForOutputToMatch('npm', ['info', 'verdaccio', '--registry' ,`http://localhost:${port}`], /verdaccio-4.3.5.tgz/); + const output = await execAndWaitForOutputToMatch('npm', ['info', 'verdaccio', '--registry'], /A lightweight private npm proxy registry/); expect(output.ok).toBeTruthy(); }); diff --git a/test/e2e-cli/utils/process.ts b/test/e2e-cli/utils/process.ts index 6b4d07377..6b50fce94 100644 --- a/test/e2e-cli/utils/process.ts +++ b/test/e2e-cli/utils/process.ts @@ -28,23 +28,25 @@ export async function _exec(options, cmd, args) { if (options.silent) { return; } + data.toString('utf-8') .split(/[\n\r]+/) .filter(line => line !== '') .forEach(line => console.log(' ' + line)); }); + childProcess.stderr.on('data', (data) => { stderr += data.toString('utf-8'); if (options.silent) { return; } + data.toString('utf-8') .split(/[\n\r]+/) .filter(line => line !== '') .forEach(line => console.error((' ' + line))); }); - // Create the error here so the stack shows who called this function. const err = new Error(`Running "${cmd} ${args.join(' ')}" returned error code `); return new Promise((resolve, reject) => { childProcess.on('exit', (error) => { @@ -59,6 +61,7 @@ export async function _exec(options, cmd, args) { if (options.waitForMatch) { const match = options.waitForMatch; childProcess.stdout.on('data', (data) => { + // console.log("-->data==>", data.toString(), data.toString().match(match)); if (data.toString().match(match)) { resolve({ok: true, stdout, stderr }); } @@ -77,7 +80,7 @@ export function execAndWaitForOutputToMatch( args: string[], match: RegExp, spawnOptions: SpawnOptions = {}): any { - return _exec({ waitForMatch: match, ...spawnOptions }, cmd, args); + return _exec({ waitForMatch: match, ...spawnOptions, silence: true }, cmd, args); } @@ -85,6 +88,10 @@ export function npm(...args) { return _exec({}, 'npm', args); } +export function runVerdaccio(cmd, installation, args, match: RegExp): any { + return _exec({ cwd: installation, silent: true, waitForMatch: match }, cmd, args); +} + export function silentNpm(...args) { return _exec({silent: true}, 'npm', args); } From dc25630ef2a444b78f75ce6b8a67f482ab99ea96 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 15 Dec 2019 23:04:11 +0100 Subject: [PATCH 11/11] test: add test for listen port --- test/e2e-cli/config/default.yaml | 6 ++-- test/e2e-cli/test/core/listen.spec.ts | 41 +++++++++++++++++++++++++++ test/e2e-cli/utils/web.ts | 23 +++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 test/e2e-cli/test/core/listen.spec.ts create mode 100644 test/e2e-cli/utils/web.ts diff --git a/test/e2e-cli/config/default.yaml b/test/e2e-cli/config/default.yaml index 39ec46bc4..e107aea83 100644 --- a/test/e2e-cli/config/default.yaml +++ b/test/e2e-cli/config/default.yaml @@ -14,7 +14,7 @@ web: title: verdaccio-default uplinks: - npmjs: + local: url: http://localhost:4873 logs: @@ -25,11 +25,11 @@ packages: access: $all publish: $anonymous unpublish: $authenticated - proxy: npmjs + proxy: local '**': access: $all publish: $all unpublish: $authenticated - proxy: npmjs + proxy: local _debug: true diff --git a/test/e2e-cli/test/core/listen.spec.ts b/test/e2e-cli/test/core/listen.spec.ts new file mode 100644 index 000000000..df92f546a --- /dev/null +++ b/test/e2e-cli/test/core/listen.spec.ts @@ -0,0 +1,41 @@ +import path from 'path'; +import fs from "fs"; +import {installVerdaccio} from "../__partials/npm_commands"; +import {spawnRegistry} from "../../utils/registry"; +import {callRegistry} from "../../utils/web"; + +describe('npm install', ()=> { + jest.setTimeout(90000); + const port = '9012'; + + // @ts-ignore + const tempRootFolder = global.__namespace.getItem('dir-root'); + const verdaccioInstall = path.join(tempRootFolder, 'verdaccio-root-install'); + let registryProcess; + const configPath = path.join(tempRootFolder, 'verdaccio.yaml'); + + beforeAll(async () => { + await installVerdaccio(verdaccioInstall); + fs.copyFileSync(path.join(__dirname, '../../config/default.yaml'), configPath); + }); + + test('should match the listing port and load metadata', async () => { + const pathVerdaccioModule = require.resolve('verdaccio/bin/verdaccio', { + paths: [verdaccioInstall] + }); + + registryProcess = await spawnRegistry(pathVerdaccioModule, + ['-c', configPath, '-l', port], + { cwd: verdaccioInstall, silent: true } + ); + + const body = await callRegistry(`http://localhost:${port}/verdaccio`); + const parsedBody = JSON.parse(body); + + expect(parsedBody.name).toEqual('verdaccio'); + }); + + afterAll(async () => { + registryProcess.kill(); + }); +}); diff --git a/test/e2e-cli/utils/web.ts b/test/e2e-cli/utils/web.ts new file mode 100644 index 000000000..e6d89f73a --- /dev/null +++ b/test/e2e-cli/utils/web.ts @@ -0,0 +1,23 @@ +import {IncomingMessage} from 'http'; +import request from 'request'; + + +export function callRegistry(url: string): Promise { + return new Promise((resolve, reject) => { + let options = { + url: url, + headers: { 'Accept': 'application/json' }, + }; + // @ts-ignore + request(options, (error: any, response: IncomingMessage, body: string) => { + if (error) { + reject(error); + // @ts-ignore + } else if (response.statusCode >= 400) { + reject(new Error(`Requesting "${url}" returned status code ${response.statusCode}.`)); + } else { + resolve(body); + } + }); + }); +}