core-annotations
Advanced tools
Comparing version 1.0.4 to 1.0.5
const gulp = require('gulp') | ||
const mocha = require('gulp-mocha') | ||
const plugins = require('gulp-load-plugins')(); | ||
gulp.task('test', () => | ||
gulp.src('./test/**/*.spec.js', { | ||
read: false | ||
}) | ||
.pipe(mocha({ | ||
reporter: 'spec' | ||
})) | ||
); | ||
const SPECS = process.env.SPECS || null; | ||
gulp.task('setup-coverage', () => { | ||
return gulp.src(['./lib/**/*.js']) | ||
.pipe(plugins['istanbul']()) | ||
.pipe(plugins['istanbul'].hookRequire()) | ||
}) | ||
gulp.task('test', ['setup-coverage'], () => { | ||
return gulp.src('./test/**/*.spec.js', { | ||
read: false | ||
}) | ||
.pipe(plugins['mocha']({ | ||
reporter: 'spec' | ||
})) | ||
.pipe(plugins['istanbul'].writeReports({ | ||
dir: './test/results/coverage' | ||
})) | ||
.pipe(plugins['istanbul'].enforceThresholds({ thresholds: { global: 90 } })) | ||
}); | ||
@@ -58,4 +58,3 @@ class Annotation { | ||
_generateAnnotations: function(annotations, src) { | ||
let key = new Date().getTime() | ||
_generateAnnotations: function(annotations, src, key = new Date().getTime()) { | ||
let targets = {} | ||
@@ -70,3 +69,3 @@ src = src.replace(/\@(\w+)\s*(\([^\(\)]+\)|\s)/g, (all, $annotation, $values) => { | ||
.replace(/^(\w+)\s*=/g, (all, $key) => `${$key}: `) | ||
.replace(/,\s*(\w+)\s*=/g, (all, $key) => `${$key}: `) | ||
.replace(/,\s*(\w+)\s*=/g, (all, $key) => `, ${$key}: `) | ||
$values = `{${$values}}` | ||
@@ -73,0 +72,0 @@ } |
{ | ||
"name": "core-annotations", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Flexible annotation parser for Node", | ||
@@ -31,2 +31,4 @@ "main": "lib/index.js", | ||
"gulp": "^3.9.1", | ||
"gulp-istanbul": "^1.1.1", | ||
"gulp-load-plugins": "^1.5.0", | ||
"gulp-mocha": "^4.0.1", | ||
@@ -33,0 +35,0 @@ "mocha": "^3.2.0" |
@@ -1,2 +0,4 @@ | ||
# core-annotations | ||
# core-annotations [![Build Status](https://travis-ci.org/henrytao-me/core-annotations.svg?branch=master)](https://travis-ci.org/henrytao-me/core-annotations) | ||
=============== | ||
Flexible annotation parser for Node | ||
@@ -3,0 +5,0 @@ |
const expect = require('chai').expect | ||
const fs = require('fs') | ||
const path = require('path') | ||
const compiler = require('../lib/compiler') | ||
const SRC = fs.readFileSync('./test/sample/myClass.js', 'utf8') | ||
describe('compiler.js', () => { | ||
let annotations = { | ||
@@ -11,15 +16,96 @@ ClassAnnotation: {}, | ||
describe('_generateAnnotations', () => { | ||
let verify = (a, b) => expect((a || '').replace(/\s+/g, ' ').trim()).to.equal((b || '').replace(/\s+/g, ' ').trim()) | ||
it('_cleanup', () => { | ||
let expected = fs.readFileSync('./test/sample/myClass.cleanup.js', 'utf8') | ||
let result = compiler._cleanup(annotations, SRC) | ||
verify(result, expected) | ||
}) | ||
describe('ClassAnnotation', () => { | ||
it('should return -1 when the value is not present', function() { | ||
expect({}).to.exist | ||
expect(26).to.equal(26) | ||
expect(false).to.be.false | ||
expect('hello').to.be.string | ||
it('_fixExport', () => { | ||
let expected = 'class TestClass { } module.exports = TestClass' | ||
let src = 'module.exports = class TestClass { } ' | ||
let result = compiler._fixExport(src) | ||
verify(result, expected) | ||
}) | ||
it('_generateAnnotations', () => { | ||
let expected = { | ||
targets: { | ||
0: { | ||
all: `@ClassAnnotation`, | ||
$annotation: `ClassAnnotation`, | ||
$values: `null` | ||
}, | ||
1: { | ||
all: `@FieldAnnotation`, | ||
$annotation: `FieldAnnotation`, | ||
$values: `null` | ||
}, | ||
2: { | ||
all: `@FieldAnnotation('injectedFieldB')`, | ||
$annotation: `FieldAnnotation`, | ||
$values: `'injectedFieldB'` | ||
}, | ||
3: { | ||
all: `@FieldAnnotation(name = 'injectedFieldC', options = { key1: 'key1', key2: variableA })`, | ||
$annotation: `FieldAnnotation`, | ||
$values: `{name: 'injectedFieldC', options: { key1: 'key1', key2: variableA }}` | ||
}, | ||
4: { | ||
all: `@MethodAnnotation`, | ||
$annotation: `MethodAnnotation`, | ||
$values: `null` | ||
}, | ||
5: { | ||
all: `@MethodAnnotation('injectedMethodB')`, | ||
$annotation: `MethodAnnotation`, | ||
$values: `'injectedMethodB'` | ||
}, | ||
6: { | ||
all: `@MethodAnnotation(name = 'injectedMethodC', options = { key1: 'key1', key2: variableA })`, | ||
$annotation: `MethodAnnotation`, | ||
$values: `{name: 'injectedMethodC', options: { key1: 'key1', key2: variableA }}` | ||
}, | ||
7: { | ||
all: `@ClassAnnotation('injectedClassB')`, | ||
$annotation: `ClassAnnotation`, | ||
$values: `'injectedClassB'` | ||
}, | ||
8: { | ||
all: `@ClassAnnotation(name = 'injectedClassC', options = { key1: 'key1', key2: variableA })`, | ||
$annotation: `ClassAnnotation`, | ||
$values: `{name: 'injectedClassC', options: { key1: 'key1', key2: variableA }}` | ||
} | ||
} | ||
} | ||
let result = compiler._generateAnnotations(annotations, fs.readFileSync('./test/sample/myClass.js', 'utf8'), 0) | ||
expect(Object.keys(result.targets)).to.have.all.keys(Object.keys(expected.targets)) | ||
Object.keys(result.targets).forEach(key => { | ||
verify(result.targets[key].all, expected.targets[key].all) | ||
verify(result.targets[key].$annotation, expected.targets[key].$annotation) | ||
verify(result.targets[key].$values, expected.targets[key].$values) | ||
}) | ||
}) | ||
it('_getClass', () => { | ||
let src = ` | ||
@{11111} | ||
class ClassA { | ||
@{33333} injectB | ||
} | ||
@{22222} | ||
class ClassB { | ||
@{44444} | ||
methodA() {} | ||
} | ||
` | ||
expect(compiler._getClass(src, '33333')).to.equal('ClassA') | ||
expect(compiler._getClass(src, '44444')).to.equal('ClassB') | ||
}) | ||
}) | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29475
14
437
144
6
3