Skip to content

Commit

Permalink
📦 Basic utils, basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed Sep 26, 2016
1 parent fd44d11 commit fc46ab4
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/src/index.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"processId": "${command.PickProcess}",
"port": 5858,
"sourceMaps": false,
"outDir": null
}
]
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "electron-windows-notifications",
"version": "0.1.0",
"description": "Native Windows notifications for Electron using NodeRT",
"main": "index.js",
"main": "./src/index.js",
"scripts": {
"test": "standard ./src"
"test": "standard \"./src/*.js\" && standard \"./test/*.js\" && mocha"
},
"repository": {
"type": "git",
Expand All @@ -23,6 +23,8 @@
},
"homepage": "https://github.com/CatalystCode/electron-windows-notifications#readme",
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.0.2",
"standard": "^8.1.0"
}
}
38 changes: 38 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const os = require('os')

const utils = {
/**
* Gets the version of Windows
* @param {string} [version=os.release()] Release value to test
*
* @returns {number} Major & minor of Windows (8.0, 8.1, 10)
*/

getWindowsVersion (version = os.release()) {
let match = version.match(/^(\d+).?(\d+).?(\*|\d+)$/)

// We got major, minor
if (match.length > 2 && match[1] === '6' && match[2] === '1') {
return '7.0'
} else if (match.length > 2 && match[1] === '6' && match[2] === '2') {
return '8.0'
} else if (match.length > 2 && match[1] === '6' && match[2] === '3') {
return '8.1'
} else if (match.length > 2 && match[1] === '10' && match[2] === '0') {
return '10.0'
} else if (match.length > 2) {
return `${match[1]}.${match[2]}`
} else {
return version
}
},

/**
* @returns {boolean} Is Windows
*/
getIsWindows (platform = os.platform()) {
return platform === 'win32'
}
}

module.exports = utils
34 changes: 34 additions & 0 deletions test/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { getWindowsVersion, getIsWindows } = require('../../src/utils')


describe('Utils', () => {
it('getWindowsVersion returns 10.0 for Windows 10', () => {
let version = getWindowsVersion('10.0.14393')
version.should.be.equal('10.0')
})

it('getWindowsVersion returns 8.1 for Windows 8.1', () => {
let version = getWindowsVersion('6.3.9600')
version.should.be.equal('8.1')
})

it('getWindowsVersion returns 8 for Windows 8', () => {
let version = getWindowsVersion('6.2.9600')
version.should.be.equal('8.0')
})

it('getWindowsVersion returns 7 for Windows 7', () => {
let version = getWindowsVersion('6.1.9600')
version.should.be.equal('7.0')
})

it('getIsWindows returns true for Windows', () => {
let platform = getIsWindows('win32')
platform.should.be.equal(true)
})

it('getIsWindows returns false for macOS', () => {
let platform = getIsWindows('darwin')
platform.should.be.equal(false)
})
})
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const chai = require('chai')

chai.should()

// Run tests
require('./src/utils')

0 comments on commit fc46ab4

Please sign in to comment.