* New translations ansible.md (Chinese Traditional) * New translations uplinks.md (Chinese Traditional, Hong Kong) * New translations ssl.md (Urdu (Pakistan)) * New translations test.md (Chinese Traditional) * New translations test.md (Chinese Traditional, Hong Kong) * New translations test.md (Portuguese, Brazilian) * New translations test.md (Spanish) * New translations test.md (Urdu (Pakistan)) * New translations uplinks.md (Chinese Traditional) * New translations uplinks.md (Portuguese, Brazilian) * New translations ssl.md (Portuguese, Brazilian) * New translations uplinks.md (Spanish) * New translations uplinks.md (Urdu (Pakistan)) * New translations use-cases.md (Chinese Traditional) * New translations use-cases.md (Chinese Traditional, Hong Kong) * New translations use-cases.md (Portuguese, Brazilian) * New translations use-cases.md (Spanish) * New translations use-cases.md (Urdu (Pakistan)) * New translations ssl.md (Spanish) * New translations ssl.md (Chinese Traditional, Hong Kong) * New translations web.md (Chinese Traditional, Hong Kong) * New translations reverse-proxy.md (Chinese Traditional, Hong Kong) * New translations protect-your-dependencies.md (Urdu (Pakistan)) * New translations repositories.md (Chinese Traditional) * New translations repositories.md (Chinese Traditional, Hong Kong) * New translations repositories.md (Portuguese, Brazilian) * New translations repositories.md (Spanish) * New translations repositories.md (Urdu (Pakistan)) * New translations reverse-proxy.md (Chinese Traditional) * New translations reverse-proxy.md (Portuguese, Brazilian) * New translations ssl.md (Chinese Traditional) * New translations reverse-proxy.md (Spanish) * New translations reverse-proxy.md (Urdu (Pakistan)) * New translations server.md (Chinese Traditional) * New translations server.md (Chinese Traditional, Hong Kong) * New translations server.md (Portuguese, Brazilian) * New translations server.md (Spanish) * New translations server.md (Urdu (Pakistan)) * New translations web.md (Chinese Traditional) * New translations web.md (Portuguese, Brazilian) * New translations protect-your-dependencies.md (Portuguese, Brazilian) * New translations repositories.md (Chinese Simplified) * New translations install.md (Chinese Simplified) * New translations kubernetes.md (Chinese Simplified) * New translations logger.md (Chinese Simplified) * New translations notifications.md (Chinese Simplified) * New translations packages.md (Chinese Simplified) * New translations plugins.md (Chinese Simplified) * New translations protect-your-dependencies.md (Chinese Simplified) * New translations reverse-proxy.md (Chinese Simplified) * New translations home.md (Chinese Simplified) * New translations server.md (Chinese Simplified) * New translations ssl.md (Chinese Simplified) * New translations test.md (Chinese Simplified) * New translations uplinks.md (Chinese Simplified) * New translations use-cases.md (Chinese Simplified) * New translations web.md (Chinese Simplified) * New translations windows.md (Chinese Simplified) * New translations iis-server.md (Chinese Simplified) * New translations docker.md (Chinese Simplified) * New translations web.md (Spanish) * New translations web.md (Urdu (Pakistan)) * New translations windows.md (Chinese Traditional) * New translations windows.md (Chinese Traditional, Hong Kong) * New translations windows.md (Portuguese, Brazilian) * New translations windows.md (Spanish) * New translations windows.md (Urdu (Pakistan)) * New translations dev-plugins.md (Chinese Simplified) * New translations ansible.md (Chinese Simplified) * New translations auth.md (Chinese Simplified) * New translations cli.md (Chinese Simplified) * New translations config.md (Chinese Simplified) * New translations contributing.md (Chinese Simplified) * New translations protect-your-dependencies.md (Spanish) * New translations protect-your-dependencies.md (Chinese Traditional, Hong Kong) * New translations ansible.md (Chinese Traditional, Hong Kong) * New translations dev-plugins.md (Chinese Traditional) * New translations config.md (Spanish) * New translations config.md (Urdu (Pakistan)) * New translations contributing.md (Chinese Traditional) * New translations contributing.md (Chinese Traditional, Hong Kong) * New translations contributing.md (Portuguese, Brazilian) * New translations contributing.md (Spanish) * New translations contributing.md (Urdu (Pakistan)) * New translations dev-plugins.md (Chinese Traditional, Hong Kong) * New translations config.md (Chinese Traditional, Hong Kong) * New translations dev-plugins.md (Portuguese, Brazilian) * New translations dev-plugins.md (Spanish) * New translations dev-plugins.md (Urdu (Pakistan)) * New translations docker.md (Chinese Traditional) * New translations docker.md (Chinese Traditional, Hong Kong) * New translations docker.md (Portuguese, Brazilian) * New translations docker.md (Spanish) * New translations config.md (Portuguese, Brazilian) * New translations config.md (Chinese Traditional) * New translations home.md (Chinese Traditional) * New translations auth.md (Urdu (Pakistan)) * New translations ansible.md (Portuguese, Brazilian) * New translations ansible.md (Spanish) * New translations ansible.md (Urdu (Pakistan)) * New translations auth.md (Chinese Traditional) * New translations auth.md (Chinese Traditional, Hong Kong) * New translations auth.md (Portuguese, Brazilian) * New translations auth.md (Spanish) * New translations cli.md (Urdu (Pakistan)) * New translations cli.md (Chinese Traditional) * New translations cli.md (Chinese Traditional, Hong Kong) * New translations cli.md (Portuguese, Brazilian) * New translations cli.md (Spanish) * New translations docker.md (Urdu (Pakistan)) * New translations home.md (Chinese Traditional, Hong Kong) * New translations protect-your-dependencies.md (Chinese Traditional) * New translations packages.md (Chinese Traditional, Hong Kong) * New translations logger.md (Urdu (Pakistan)) * New translations notifications.md (Chinese Traditional) * New translations notifications.md (Chinese Traditional, Hong Kong) * New translations notifications.md (Portuguese, Brazilian) * New translations notifications.md (Spanish) * New translations notifications.md (Urdu (Pakistan)) * New translations packages.md (Chinese Traditional) * New translations packages.md (Portuguese, Brazilian) * New translations logger.md (Portuguese, Brazilian) * New translations packages.md (Spanish) * New translations packages.md (Urdu (Pakistan)) * New translations plugins.md (Chinese Traditional) * New translations plugins.md (Chinese Traditional, Hong Kong) * New translations plugins.md (Portuguese, Brazilian) * New translations plugins.md (Spanish) * New translations plugins.md (Urdu (Pakistan)) * New translations logger.md (Spanish) * New translations logger.md (Chinese Traditional, Hong Kong) * New translations home.md (Portuguese, Brazilian) * New translations install.md (Chinese Traditional) * New translations home.md (Spanish) * New translations home.md (Urdu (Pakistan)) * New translations iis-server.md (Chinese Traditional) * New translations iis-server.md (Chinese Traditional, Hong Kong) * New translations iis-server.md (Portuguese, Brazilian) * New translations iis-server.md (Spanish) * New translations iis-server.md (Urdu (Pakistan)) * New translations install.md (Chinese Traditional, Hong Kong) * New translations logger.md (Chinese Traditional) * New translations install.md (Portuguese, Brazilian) * New translations install.md (Spanish) * New translations install.md (Urdu (Pakistan)) * New translations kubernetes.md (Chinese Traditional) * New translations kubernetes.md (Chinese Traditional, Hong Kong) * New translations kubernetes.md (Portuguese, Brazilian) * New translations kubernetes.md (Spanish) * New translations kubernetes.md (Urdu (Pakistan))
5.2 KiB
id | title |
---|---|
unit-testing | Unit Testing |
All tests are split in three folders:
test/unit
- Tests that cover functions that transform data in an non-trivial way. These tests simplyrequire()
a few files and run code in there, so they are very fast.test/functional
- Tests that launch a verdaccio instance and perform a series of requests to it over http. They are slower than unit tests.test/integration
- Tests that launch a verdaccio instance and do requests to it using npm. They are really slow and can hit a real npm registry. **This actually has not been tested or
Unit and functional tests are executed automatically by running npm test
from the project's root directory. Integration tests are supposed to be executed manually from time to time.
We use jest
for all test.
The npm Script
To run the test script you can use either npm
or yarn
.
yarn run test
That will trigger only two first groups of test, unit and functional.
Using test/unit
The following is just an example how a unit test should looks like. Basically follow the mocha
standard. Try to describe what exactly does the unit test in a single sentence in the header of the it
section.
'use strict';
let assert = require('assert');
let parseInterval = require('../../src/lib/utils').parseInterval;
describe('Parse interval', function() {
before(function(done) {
..... some magic stuff before the show
});
it('server should respond on /', function(done) {
... this is an async test
});});
Using test/functional
Funtional testing in verdaccio has a bit more of complextity that needs a deep explanation in order to success in your experience.
All starts in the index.js
file. Let's dive in into it.
// create 3 server instances
require('./lib/startup');
...
describe('functional test verdaccio', function() {
// recover the server instances
const server = process.server;
const server2 = process.server2;
const server3 = process.server3;
// On start initialise 3 verdaccio servers
before(function(done) {
Promise.all([
require('./lib/startup').start('./store/test-storage', '/store/config-1.yaml'),
require('./lib/startup').start('./store/test-storage2', '/store/config-2.yaml'),
require('./lib/startup').start('./store/test-storage3', '/store/config-3.yaml'),
]).then(() => {
done();
}).catch(function(error) {
console.error("error on start servers", error);
});
});
before(function() {
return Promise.all([server, server2, server3].map(function(server) {
// save a lsof -p output in order to compare on finish on finish all test
}));
});
..........
// here is the unique line you should add, the new functional test.
require('./my-functional-test.js')();
// On finish kill all server
after(function(done) {
Promise.all([check(server), check(server2), check(server3)]).then(function() {
done();
}, (reason) => {
assert.equal(reason, null);
done();
});
});
});
Perhaps this is not he best approach, but, it's how works right now. So, you just learnt how the bootstrap works and how to add a new group of functional tests.
The lib/server.js
The server class is just a wrapper that simulates a npm
client and provides a simple API for the funtional test.
As we mention in the previous section, we are creating 3 process servers that are accessible in each process as process.server;
, process.server2;
and ``process.server3;`.
Using such reference you will be able to send request to any of the 3 instance running.
The lib/startup.js
The startup file is the responsable to create the 3 verdaccio instances and inject them to the process.x
global variable.
The lib/request.js
This module holds a PromiseAssert
which extends from Promise
adding methods to handle all request from lib/server.js
.
Usage
Here we are gonna describe how it looks like an usual functional test, check inline for more detail information.
'use strict';
module.exports = function() {
// you can access the 3 instance through process global variables
const server = process.server;
const server2 = process.server2;
describe('my-functional-group-test', function() {
before(function() {
// create a raw emtpy package
const pkg = require('./fixtures/package')('new-package');
return server.putPackage('new-package', pkg)
// check whether was uploaded correctly
.status(201)
// check whether body response is ok
.body_ok(/created new package/);
});
// since before are not registred, we use emtpy it to display before putPackage was success
it('creating new package / srv1', function() {});
it('should do something else here ..... ', function() {
// this should fails since fakeVersion does not exist
// note we use server2 because is an uplink of server 1
return server2.getTarball('new-package', 'fakeVersion')
.status(404)
.body_error(/no such file/);
});
});
};
Test/integration
These section never has been used, but we are looking for help to make it run properly. All new ideas are very welcome.