add tests
Gitnet/scraper/pipeline/head There was a failure building this commit Details

This commit is contained in:
Simon Vieille 2020-09-02 10:44:33 +02:00
parent 5619191a00
commit 62da111aca
Signed by: deblan
GPG Key ID: 03383D15A1D31745
6 changed files with 78 additions and 2 deletions

13
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,13 @@
pipeline {
agent any
stages {
stage('mocha') {
steps {
sh 'npm install --dev'
sh 'npm run test'
}
}
}
}

View File

@ -3,7 +3,9 @@
"description": "Web scraper using CSS selector",
"version": "1.1.0",
"main": "src/index.js",
"devDependencies": {},
"devDependencies": {
"mocha": "^8.1.3"
},
"dependencies": {
"cheerio": "^1.0.0-rc.3",
"extends-classes": "^1.0.5",
@ -14,7 +16,7 @@
"trim": "^0.0.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},
"repository": {
"type": "git",

20
test/breaks.test.js Normal file
View File

@ -0,0 +1,20 @@
const filter = require('../src/filter/breaks')
const assert = require('assert')
describe('Check "breaks"', () => {
it('Should return empty string', () => {
assert.equal(filter("\n"), "")
})
it('Should return empty string', () => {
assert.equal(filter("\r"), "")
})
it('Should return "foo"', () => {
assert.equal(filter("foo"), "foo")
})
it('Should return "foobar"', () => {
assert.equal(filter("\r\nfoo\nbar\r\n"), "foobar")
})
});

16
test/spaces.test.js Normal file
View File

@ -0,0 +1,16 @@
const filter = require('../src/filter/spaces')
const assert = require('assert')
describe('Check "spaces"', () => {
it('Should return ""', () => {
assert.equal(filter(""), "")
})
it('Should return "foo bar"', () => {
assert.equal(filter("foo bar"), "foo bar")
})
it('Should return "foo bar"', () => {
assert.equal(filter("foo \nbar"), "foo bar")
})
});

5
test/tags.test.js Normal file
View File

@ -0,0 +1,5 @@
const filter = require('../src/filter/tags')
const assert = require('assert')
describe('Check "tags"', () => {
});

20
test/trim.test.js Normal file
View File

@ -0,0 +1,20 @@
const filter = require('../src/filter/trim')
const assert = require('assert')
describe('Check "trim"', () => {
it('Should return ""', () => {
assert.equal(filter(""), "")
})
it('Should return ""', () => {
assert.equal(filter(" "), "")
})
it('Should return "foo"', () => {
assert.equal(filter(" foo "), "foo")
})
it('Should return "foo bar"', () => {
assert.equal(filter(" foo bar \n"), "foo bar")
})
});