Browse Source

add tests

develop
Simon Vieille 6 months ago
parent
commit
62da111aca
Signed by: deblan GPG Key ID: 03383D15A1D31745
6 changed files with 78 additions and 2 deletions
  1. +13
    -0
      Jenkinsfile
  2. +4
    -2
      package.json
  3. +20
    -0
      test/breaks.test.js
  4. +16
    -0
      test/spaces.test.js
  5. +5
    -0
      test/tags.test.js
  6. +20
    -0
      test/trim.test.js

+ 13
- 0
Jenkinsfile View File

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

+ 4
- 2
package.json 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
- 0
test/breaks.test.js 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
- 0
test/spaces.test.js 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
- 0
test/tags.test.js View File

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

+ 20
- 0
test/trim.test.js 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")
})
});

Loading…
Cancel
Save