Skip to content

Commit 2bae57f

Browse files
authored
Merge pull request #4 from inspekter/develop
Develop
2 parents 8c078ab + aa9b768 commit 2bae57f

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const escomplex = require('escomplex')
44
const path = require('path')
5+
const read = require('read-file')
56

67
function sanitize (fileName, filePath, result) {
78
return {
@@ -35,11 +36,17 @@ module.exports.analyze = (source) => {
3536

3637
if (Array.isArray(source)) {
3738
source.forEach((filePath) => {
38-
result = escomplex.analyse(filePath)
39+
let fullPath = path.resolve(__dirname, filePath)
40+
let content = read.sync(fullPath, 'utf8')
41+
result = escomplex.analyse(content)
3942
report = sanitize(path.basename(filePath), filePath, result)
4043
reports.push(report)
4144
})
4245
}
4346

4447
return reports
4548
}
49+
50+
module.exports.getExtension = () => {
51+
return 'js'
52+
}

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "inspekter-plugin-javascript",
3-
"version": "0.0.1",
2+
"name": "@inspekter/inspekter-plugin-javascript",
3+
"version": "1.0.0",
44
"description": "Inspekter JavaScript reporter",
55
"main": "index.js",
66
"scripts": {
@@ -10,8 +10,8 @@
1010
"type": "git",
1111
"url": "git+https://github.com/inspekter/inspekter-plugin-javascript.git"
1212
},
13-
"engines" : {
14-
"node" : ">=4"
13+
"engines": {
14+
"node": ">=4"
1515
},
1616
"author": "Pablo Oliveira <kryptogeist@gmail.com>",
1717
"license": "MIT",
@@ -20,7 +20,8 @@
2020
},
2121
"homepage": "https://github.com/inspekter/inspekter-plugin-javascript#readme",
2222
"dependencies": {
23-
"escomplex": "^2.0.0-alpha"
23+
"escomplex": "^2.0.0-alpha",
24+
"read-file": "^0.2.0"
2425
},
2526
"devDependencies": {
2627
"chai": "^4.1.2",

test/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,36 @@ const properties = [
6767
describe('inspekter-plugin-javascript', () => {
6868
describe('analyze', () => {
6969
it('should always return an array', () => {
70-
const source = ['fixtures/file1.js']
70+
const source = ['test/fixtures/file1.js']
7171
const actual = ipj.analyze(source)
7272

7373
expect(actual).to.be.an('array')
7474
expect(actual).to.have.lengthOf(1)
7575
})
7676

7777
it('should return one report object for each file', () => {
78-
const source = ['fixtures/file1.js', 'fixtures/file2.js']
78+
const source = ['test/fixtures/file1.js', 'test/fixtures/file2.js']
7979
const actual = ipj.analyze(source)
8080

8181
expect(actual).to.be.an('array')
8282
expect(actual).to.have.lengthOf(2)
8383
})
8484

8585
it('should return an object with all standard properties', () => {
86-
const source = ['fixtures/file1.js']
86+
const source = ['test/fixtures/file1.js']
8787
const actual = ipj.analyze(source)[0]
8888

8989
properties.forEach((property) => {
9090
expect(actual).to.have.nested.property(property.name).that.is.a(property.type)
9191
})
9292
})
9393
})
94+
95+
describe('getExtension', () => {
96+
it('should return js', () => {
97+
const actual = ipj.getExtension()
98+
99+
expect(actual).to.equal('js')
100+
})
101+
})
94102
})

0 commit comments

Comments
 (0)