npmci/test/test.ts

103 lines
3.3 KiB
TypeScript
Raw Permalink Normal View History

2016-11-14 23:07:55 +00:00
import 'typings-test'
import * as should from 'should'
import path = require('path')
import * as beautylog from 'beautylog'
// set up environment
process.env.CI_BUILD_REPO = 'https://yyyyyy:xxxxxxxx@gitlab.com/mygroup/myrepo.git'
process.env.NPMCI_SSHKEY_1 = 'hostString|somePrivKey|##'
process.env.NPMTS_TEST = 'true'
2016-06-05 11:01:45 +00:00
process.cwd = () => {
2016-11-14 23:07:55 +00:00
return path.join(__dirname,'assets/')
}
// require NPMCI files
import npmci = require('../dist/index')
import NpmciBuildDocker = require('../dist/npmci.build.docker')
import NpmciPublish = require('../dist/npmci.publish')
import NpmciTest = require('../dist/npmci.test')
import NpmciSsh = require('../dist/npmci.ssh')
2016-06-05 11:01:45 +00:00
2016-11-14 23:07:55 +00:00
let dockerfile1: NpmciBuildDocker.Dockerfile
let dockerfile2: NpmciBuildDocker.Dockerfile
let sortableArray: NpmciBuildDocker.Dockerfile[]
2016-06-05 11:01:45 +00:00
2016-11-14 23:07:55 +00:00
describe('NPMCI',function(){
describe('build.docker',function(){
it('should return valid Dockerfiles',function(){
dockerfile1 = new NpmciBuildDocker.Dockerfile({filePath: './Dockerfile', read: true})
dockerfile2 = new NpmciBuildDocker.Dockerfile({filePath: './Dockerfile_sometag1', read: true})
should(dockerfile1.version).equal('latest')
should(dockerfile2.version).equal('sometag1')
})
2016-06-05 11:01:45 +00:00
2016-11-14 23:07:55 +00:00
it('should read a directory of Dockerfiles',function(done){
2016-06-05 11:01:45 +00:00
NpmciBuildDocker.readDockerfiles()
2016-11-14 23:07:55 +00:00
.then(function(readDockerfilesArrayArg: NpmciBuildDocker.Dockerfile[]){
should(readDockerfilesArrayArg[1].version).equal('sometag1')
2016-06-05 11:01:45 +00:00
sortableArray = readDockerfilesArrayArg
2016-11-14 23:07:55 +00:00
done()
})
2016-06-05 11:01:45 +00:00
})
2016-11-14 23:07:55 +00:00
it('should sort an array of Dockerfiles',function(done){
2016-06-05 11:01:45 +00:00
NpmciBuildDocker.sortDockerfiles(sortableArray)
2016-11-14 23:07:55 +00:00
.then(function(sortedArrayArg: NpmciBuildDocker.Dockerfile[]){
beautylog.success('final result')
console.log(sortedArrayArg)
done()
2016-06-05 11:01:45 +00:00
})
2016-11-14 23:07:55 +00:00
})
it('should correctly chain Dockerfile handling', function(done){
2016-06-05 12:55:08 +00:00
NpmciBuildDocker.build()
2016-11-14 23:07:55 +00:00
.then(() => {
done()
})
2016-06-05 11:01:45 +00:00
})
2016-11-14 23:07:55 +00:00
})
describe('.publish.docker',function(){
it('should publish all built Dockerfiles',function(done){
NpmciPublish.publish('docker')
2016-06-05 15:17:15 +00:00
.then(() => {
2016-11-14 23:07:55 +00:00
done()
})
})
})
describe('.test.npm',function(){
it('should source nvm using bash and install a specific node version, then test it',function(done){
NpmciTest.test('legacy')
2016-06-05 14:56:07 +00:00
.then(() => {
2016-11-14 23:07:55 +00:00
return NpmciTest.test('lts')
2016-06-05 14:56:07 +00:00
})
.then(() => {
2016-11-14 23:07:55 +00:00
return NpmciTest.test('stable')
2016-06-05 14:56:07 +00:00
})
.then(() => {
2016-11-14 23:07:55 +00:00
done()
})
2016-06-07 02:31:25 +00:00
})
2016-11-14 23:07:55 +00:00
})
describe('test.docker',function(){
it('should test dockerfiles',function(done){
NpmciTest.test('docker')
2016-06-05 14:56:07 +00:00
.then(() => {
2016-11-14 23:07:55 +00:00
done()
})
2016-06-05 14:56:07 +00:00
})
2016-11-14 23:18:32 +00:00
})
2016-11-14 23:07:55 +00:00
describe('npmci prepare ssh',function(){
it('should pick up SSH keys',function(done){
2016-06-26 00:17:17 +00:00
NpmciSsh.ssh()
.then(() => {
2016-11-14 23:07:55 +00:00
done()
2016-06-26 00:17:17 +00:00
})
})
})
2016-11-14 23:07:55 +00:00
})