Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix install #15

Merged
merged 3 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_js:
script:
- npm install
- npm run lint
- npm run build
- npm run coverage
after_success: npm run coveralls
notifications:
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ActiveForUserWithEmailStrategy extends Strategy {

const client = initialize({
url: 'http://unleash.herokuapp.com/features',
refreshIntervall: 10000,
refreshInterval: 10000,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing as this typo was present in the old version as well, maybe we should do something like

console.log('Passed in `refreshIntervall`, please use `refreshInterval` instead');

and map it? Making migration from old to new easier

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sure add this.

strategies: [new ActiveForUserWithEmailStrategy()],
});

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"lint": "eslint .",
"build": "tsc src/*.ts -d --strictNullChecks --sourceMap --outdir ./lib --lib ES6,ES5",
"postinstall": "npm run build",
"prepublish": "not-in-install && npm run build || in-install",
"test": "ava test",
"coverage": "nyc --check-coverage=true npm test",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
Expand All @@ -29,7 +29,7 @@
"request": "^2.74.0"
},
"engines": {
"node": "6"
"node": ">=6"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You test on node 4, though, why lock it to 6?

},
"files": [
"lib",
Expand All @@ -42,6 +42,7 @@
"coveralls": "^2.11.2",
"eslint": "^3.3.1",
"eslint-config-finn": "^1.0.0-alpha.9",
"in-publish": "^2.0.0",
"mkdirp": "^0.5.1",
"nock": "^1.2.1",
"nyc": "^8.3.0",
Expand Down
8 changes: 4 additions & 4 deletions src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Repository extends EventEmitter implements EventEmitter {
private storage: Storage;
private etag: string;

constructor (backupPath: string, url: string, refreshIntervall?: number, StorageImpl = Storage) {
constructor (backupPath: string, url: string, refreshInterval?: number, StorageImpl = Storage) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change, I suppose...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New client is breaking, so fine to fix this as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

super();
if (!url.startsWith('http')) {
throw new Error(`Wrong url: ${url}`);
Expand All @@ -24,8 +24,8 @@ export default class Repository extends EventEmitter implements EventEmitter {

process.nextTick(() => this.fetch());

if (refreshIntervall != null && refreshIntervall > 0) {
this.timer = setInterval(() => this.fetch(), refreshIntervall);
if (refreshInterval != null && refreshInterval > 0) {
this.timer = setInterval(() => this.fetch(), refreshInterval);
this.timer.unref();
}
}
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class Repository extends EventEmitter implements EventEmitter {
}

if (res.statusCode !== 200) {
return this.emit('error', new Error('Reponse was not statusCode 200'));
return this.emit('error', new Error('Response was not statusCode 200'));
}

try {
Expand Down
8 changes: 4 additions & 4 deletions src/unleash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BACKUP_PATH: string = tmpdir();

export interface UnleashConfig {
url: string;
refreshIntervall?: number;
refreshInterval?: number;
backupPath?: string;
strategies: Strategy[];
errorHandler?: (err: any) => any;
Expand All @@ -23,7 +23,7 @@ export class Unleash extends EventEmitter {

constructor({
url,
refreshIntervall = 15 * 1000,
refreshInterval = 15 * 1000,
backupPath = BACKUP_PATH,
strategies = [],
errorHandler = () => {}
Expand All @@ -34,7 +34,7 @@ export class Unleash extends EventEmitter {
throw new Error('Unleash server URL missing');
}

this.repository = new Repository(backupPath, url, refreshIntervall);
this.repository = new Repository(backupPath, url, refreshInterval);

this.repository.on('error', (err) => {
this.emit('error', err);
Expand All @@ -58,7 +58,7 @@ export class Unleash extends EventEmitter {
return this.client.isEnabled(name, context, fallbackValue);
} else {
const returnValue = typeof fallbackValue === 'boolean' ? fallbackValue : false;
this.emit('warn', `Unleash has not been initalized yet. isEnabled(${name}) defaulted to ${returnValue}`);
this.emit('warn', `Unleash has not been initialized yet. isEnabled(${name}) defaulted to ${returnValue}`);
return returnValue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ test('should emit error when invalid feature runtime', (t) => {
return {
name: 'feature-wrong-strategy',
enabled: true,
strategies: [{ name: 'non-existant' }],
strategies: [{ name: 'non-existent' }],
};
},
};
Expand Down
4 changes: 2 additions & 2 deletions test/repository.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test.cb('should handle 404 request error and emit error event', (t) => {

repo.on('error', (err) => {
t.truthy(err);
t.true(err.message.startsWith('Reponse was not statusCode 200'));
t.true(err.message.startsWith('Response was not statusCode 200'));
t.end();
});
});
Expand All @@ -138,7 +138,7 @@ test('should handle invalid JSON response', (t) => new Promise((resolve, reject)
const url = 'http://unleash-test-7.app';
nock(url).persist()
.get('/features')
.reply(200, '{"INvalid payload');
.reply(200, '{"Invalid payload');
const repo = new Repository('foo', `${url}/features`, 0, MockStorage);
repo.on('error', (err) => {
t.truthy(err);
Expand Down
6 changes: 3 additions & 3 deletions test/storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function setup (name) {
return storage;
}

test('should load content from backupfile', (t) => new Promise((resolve, reject) => {
test('should load content from backup file', (t) => new Promise((resolve, reject) => {
const tmp = join(tmpdir(), 'backup-file-test');
mkdirp.sync(tmp);
const storage = new Storage(tmp);
Expand All @@ -37,7 +37,7 @@ test('should load content from backupfile', (t) => new Promise((resolve, reject)
}));


test.cb('should emit error when non-existant target backupPath', (t) => {
test.cb('should emit error when non-existent target backupPath', (t) => {
const storage = new Storage(join(tmpdir(), `random-${Math.round(Math.random() * 10000)}`));
storage.reset({ random: Math.random() });
storage.on('error', (err) => {
Expand All @@ -59,7 +59,7 @@ test.cb('should emit error when stored data is invalid', (t) => {
});
});

test('should not write content from backupfile if ready has been fired', (t) => new Promise((resolve, reject) => {
test('should not write content from backup file if ready has been fired', (t) => new Promise((resolve, reject) => {
const tmp = join(tmpdir(), 'ignore-backup-file-test');
mkdirp.sync(tmp);
const storage = new Storage(tmp);
Expand Down
2 changes: 1 addition & 1 deletion test/unleash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test('should consider unknown feature-toggle as disabled', (t) => new Promise((r
}));


test('should return fallbackvalue until online', (t) => new Promise((resolve, reject) => {
test('should return fallback value until online', (t) => new Promise((resolve, reject) => {
mockNetwork();
const instance = new Unleash({
url: 'http://unleash.app/features',
Expand Down