Skip to content

Commit

Permalink
add jest test framework (#4)
Browse files Browse the repository at this point in the history
* add jest test framework

* update readme

* update lockfile

* remove old node versions

* version update
  • Loading branch information
fscherwi authored Oct 4, 2018
1 parent adbe9b8 commit 4d01833
Show file tree
Hide file tree
Showing 7 changed files with 5,696 additions and 66 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ sudo: false
node_js:
- "node"
- "--lts"
- "0.12"
notifications:
email: false
install:
- npm install coveralls istanbul
- npm install
script:
- npm run test
- npm test
after_script:
- ./node_modules/.bin/istanbul cover test.js
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,126 +33,126 @@ console.log(useragent.firefox(62, 'Macintosh; Intel Mac OS X 10.14'));
```javascript
var useragent = require('get-user-agent');

console.log(useragent.firefoxAdvanced(version = '41.0', GeckoVersion = '20100101', SysInfo = 'Macintosh; Intel Mac OS X 10.11'));
console.log(useragent.firefoxAdvanced(version = '41.0', geckoVersion = '20100101', sysInfo = 'Macintosh; Intel Mac OS X 10.11'));
```

## API

### chrome(version, SysInfo)
### chrome(version, sysInfo)

**version**

Type: `String`, `Number`

**SysInfo**
**sysInfo**

Type: `String`

Default: data from system

### chromeAdvanced(version, WebkitVersion, SysInfo)
### chromeAdvanced(version, webkitVersion, sysInfo)

**version**

Type: `String`, `Number`

**WebkitVersion**
**webkitVersion**

Type: `String`, `Number`

**SysInfo**
**sysInfo**

Type: `String`

Default: data from system

### firefox(version, SysInfo)
### firefox(version, sysInfo)

**version**

Type: `String`, `Number`

**SysInfo**
**sysInfo**

Type: `String`

Default: data from system

### firefoxAdvanced(version, GeckoVersion, SysInfo)
### firefoxAdvanced(version, geckoVersion, sysInfo)

**version**

Type: `String`, `Number`

**GeckoVersion**
**geckoVersion**

Type: `String`, `Number`

**SysInfo**
**sysInfo**

Type: `String`

Default: data from system

### opera(version, SysInfo)
### opera(version, sysInfo)

**version**

Type: `String`, `Number`

**SysInfo**
**sysInfo**

Type: `String`

Default: data from system

### operaAdvanced(version, OperaVersion, PrestoVersion, SysInfo)
### operaAdvanced(version, operaVersion, prestoVersion, sysInfo)

**version**

Type: `String`, `Number`

**OperaVersion**
**operaVersion**

Type: `String`, `Number`

**PrestoVersion**
**prestoVersion**

Type: `String`, `Number`

**SysInfo**
**sysInfo**

Type: `String`

Default: data from system

### safari(version, SysInfo)
### safari(version, sysInfo)

**version**

Type: `String`, `Number`

**SysInfo**
**sysInfo**

Type: `String`

Default: data from system

### safariAdvanced(version, WebkitBuildVersion, SafariBuildVersion, SysInfo)
### safariAdvanced(version, webkitBuildVersion, safariBuildVersion, sysInfo)

**version**

Type: `String`, `Number`

**WebkitBuildVersion**
**webkitBuildVersion**

Type: `String`, `Number`

**SafariBuildVersion**
**safariBuildVersion**

Type: `String`, `Number`

**SysInfo**
**sysInfo**

Type: `String`

Expand Down
38 changes: 19 additions & 19 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function getSysInfo(SysInfo) { /* istanbul ignore next */
if (SysInfo) {
return SysInfo;
function getsysInfo(sysInfo) { /* istanbul ignore next */
if (sysInfo) {
return sysInfo;
} else {
var os = require("os");
switch (os.platform()) {
Expand Down Expand Up @@ -32,28 +32,28 @@ function getSysInfo(SysInfo) { /* istanbul ignore next */
}
}
module.exports = {
chrome: function chrome(version, SysInfo) {
return "Mozilla/5.0" + " (" + getSysInfo(SysInfo) + ")" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + version + " Safari/537.36";
chrome: function chrome(version, sysInfo) {
return "Mozilla/5.0" + " (" + getsysInfo(sysInfo) + ")" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/" + version + " Safari/537.36";
},
chromeAdvanced: function chromeAdvanced(version, WebkitVersion, SysInfo) {
return "Mozilla/5.0" + " (" + getSysInfo(SysInfo) + ")" + " AppleWebKit/" + WebkitVersion + " (KHTML, like Gecko) Chrome/" + version + " Safari/" + WebkitVersion;
chromeAdvanced: function chromeAdvanced(version, webkitVersion, sysInfo) {
return "Mozilla/5.0" + " (" + getsysInfo(sysInfo) + ")" + " AppleWebKit/" + webkitVersion + " (KHTML, like Gecko) Chrome/" + version + " Safari/" + webkitVersion;
},
firefox: function firefox(version, SysInfo) {
return "Mozilla/5.0" + " (" + getSysInfo(SysInfo) + "; rv:" + version + ")" + " Gecko/20100101 Firefox/" + version;
firefox: function firefox(version, sysInfo) {
return "Mozilla/5.0" + " (" + getsysInfo(sysInfo) + "; rv:" + version + ")" + " Gecko/20100101 Firefox/" + version;
},
firefoxAdvanced: function firefoxAdvanced(version, GeckoVersion, SysInfo) {
return "Mozilla/5.0" + " (" + getSysInfo(SysInfo) + "; rv:" + version + ")" + " Gecko/" + GeckoVersion + " Firefox/" + version;
firefoxAdvanced: function firefoxAdvanced(version, geckoVersion, sysInfo) {
return "Mozilla/5.0" + " (" + getsysInfo(sysInfo) + "; rv:" + version + ")" + " Gecko/" + geckoVersion + " Firefox/" + version;
},
opera: function opera(version, SysInfo) {
return "Opera/9.80 (" + getSysInfo(SysInfo) + ") Presto/2.12.388 Version/" + version;
opera: function opera(version, sysInfo) {
return "Opera/9.80 (" + getsysInfo(sysInfo) + ") Presto/2.12.388 Version/" + version;
},
operaAdvanced: function operaAdvanced(version, PrestoVersion, OperaVersion, SysInfo) {
return "Opera/" + OperaVersion + " (" + getSysInfo(SysInfo) + ") Presto/" + PrestoVersion + " Version/" + version;
operaAdvanced: function operaAdvanced(version, prestoVersion, operaVersion, sysInfo) {
return "Opera/" + operaVersion + " (" + getsysInfo(sysInfo) + ") Presto/" + prestoVersion + " Version/" + version;
},
safari: function safari(version, SysInfo) {
return "Mozilla/5.0 (" + getSysInfo(SysInfo) + ") AppleWebKit/601.4.8 (KHTML, like Gecko) Version/" + version + " Safari/601.4.8";
safari: function safari(version, sysInfo) {
return "Mozilla/5.0 (" + getsysInfo(sysInfo) + ") AppleWebKit/601.4.8 (KHTML, like Gecko) Version/" + version + " Safari/601.4.8";
},
safariAdvanced: function safariAdvanced(version, WebkitBuildVersion, SafariBuildVersion, SysInfo) {
return "Mozilla/5.0 (" + getSysInfo(SysInfo) + ") AppleWebKit/" + WebkitBuildVersion + " (KHTML, like Gecko) Version/" + version + " Safari/" + SafariBuildVersion;
safariAdvanced: function safariAdvanced(version, webkitBuildVersion, safariBuildVersion, sysInfo) {
return "Mozilla/5.0 (" + getsysInfo(sysInfo) + ") AppleWebKit/" + webkitBuildVersion + " (KHTML, like Gecko) Version/" + version + " Safari/" + safariBuildVersion;
}
};
65 changes: 65 additions & 0 deletions main.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var useragent = require('./main.js');
var parser = require('ua-parser-js');
var ua;

test('Chrome', () => {
var version = '41.0.2228.0';
ua = parser(useragent.chrome(version));
expect(ua.browser.name).toBe('Chrome');
expect(ua.browser.version).toBe(version);
});

test('Chrome Advanced', () => {
var version = '41.0.2228.0';
var webkitVersion = '537.36';
ua = parser(useragent.chromeAdvanced(version, webkitVersion));
expect(ua.browser.name).toBe('Chrome');
expect(ua.browser.version).toBe(version);
});

test('Firefox', () => {
var version = '41.0';
ua = parser(useragent.firefox(version));
expect(ua.browser.name).toBe('Firefox');
expect(ua.browser.version).toBe(version);
});

test('Firefox Advanced', () => {
var version = '41.0';
var geckoVersion = '20100101';
ua = parser(useragent.firefoxAdvanced(version, geckoVersion));
expect(ua.browser.name).toBe('Firefox');
expect(ua.browser.version).toBe(version);
});

test('Opera', () => {
var version = '12.6';
ua = parser(useragent.opera(version));
expect(ua.browser.name).toBe('Opera');
expect(ua.browser.version).toBe(version);
});

test('Opera Advanced', () => {
var version = '12.6';
var prestoVersion = '2.12.388';
var operaVersion = '9.80';
ua = parser(useragent.operaAdvanced(version, prestoVersion));
expect(ua.browser.name).toBe('Opera');
expect(ua.browser.version).toBe(version);
});

test('Safari', () => {
var version = '10.0.3';
ua = parser(useragent.safari(version));
expect(ua.browser.name).toBe('Safari');
expect(ua.browser.version).toBe(version);
});

test('Safari Advanced', () => {
var version = '10.0.3';
var webkitBuildVersion = '602.4.8';
var safariBuildVersion = '602.4.8';
ua = parser(useragent.safariAdvanced(version, webkitBuildVersion, safariBuildVersion));
expect(ua.browser.name).toBe('Safari');
expect(ua.browser.version).toBe(version);
});
Loading

0 comments on commit 4d01833

Please sign in to comment.