diff --git a/lib/actor.js b/lib/actor.js index e365892..463eddc 100644 --- a/lib/actor.js +++ b/lib/actor.js @@ -4,7 +4,7 @@ const systemMap = require('./system-map'); const { ActorReference, TemporaryReference, Nobody } = require('./references'); const Queue = require('denque'); const assert = require('assert'); -const freeze = require('deep-freeze-node'); +const freeze = require('./freeze'); const { Subject } = require('rxjs'); const { stop } = require('./functions'); const { defaultSupervisionPolicy, SupervisionActions } = require('./supervision'); diff --git a/lib/paths.js b/lib/paths.js index 25fe9ab..bc15247 100644 --- a/lib/paths.js +++ b/lib/paths.js @@ -1,4 +1,4 @@ -const freeze = require('deep-freeze-node'); +const freeze = require('./freeze'); class ActorPath { constructor (parts) { diff --git a/lib/persistence/persistence-engine.js b/lib/persistence/persistence-engine.js index 4fb566e..11dcedb 100644 --- a/lib/persistence/persistence-engine.js +++ b/lib/persistence/persistence-engine.js @@ -1,4 +1,4 @@ -const freeze = require('deep-freeze-node'); +const freeze = require('../freeze'); const assert = require('assert'); class AbstractPersistenceEngine { diff --git a/lib/persistence/persistent-actor.js b/lib/persistence/persistent-actor.js index b90df0a..0aa6949 100644 --- a/lib/persistence/persistent-actor.js +++ b/lib/persistence/persistent-actor.js @@ -1,7 +1,7 @@ require('rxjs'); const { PersistedEvent, PersistedSnapshot } = require('./persistence-engine'); const { Actor } = require('../actor'); -const freeze = require('deep-freeze-node'); +const freeze = require('../freeze'); const { applyOrThrowIfStopped } = require('../system-map'); class PersistentActor extends Actor { diff --git a/lib/references.js b/lib/references.js index 2b5b90d..a65732f 100644 --- a/lib/references.js +++ b/lib/references.js @@ -1,4 +1,4 @@ -const freeze = require('deep-freeze-node'); +const freeze = require('./freeze'); class Nobody { constructor () { diff --git a/test/freeze.js b/test/freeze.js new file mode 100644 index 0000000..be822e7 --- /dev/null +++ b/test/freeze.js @@ -0,0 +1,69 @@ +/* eslint-env mocha */ +/* eslint-disable no-unused-expressions */ +var freeze = require('../lib/freeze'); +require('chai').should(); + +describe('freeze', function () { + let person = {}; + let expectedPerson = {}; + + beforeEach(function () { + person = { + name: 'John', + surname: 'Johnson', + age: 26, + address: { + street: '1st Street', + city: 'Los Angeles', + country: 'USA' + }, + vehicles: ['BMW', 'Ferrari', 'Lamborghini'] + }; + + expectedPerson = { + name: 'John', + surname: 'Johnson', + age: 26, + address: { + street: '1st Street', + city: 'Los Angeles', + country: 'USA' + }, + vehicles: ['BMW', 'Ferrari', 'Lamborghini'] + }; + }); + + it('should not override any object properties', function () { + person = freeze(person); + person.name = 'Jack'; + person.surname = 'Jackson'; + person.age = 18; + person.address = { + street: 'Third Street', + city: 'San Francisco', + country: 'USA' + }; + person.vehicles = ['Toyota']; + person.name = 'Jack'; + person.surname = 'Jackson'; + person.age = 18; + person.address.street = 'Third Street'; + person.address.city = 'San Francisco'; + person.address.country = 'USA'; + person.vehicles[0] = 'Toyota'; + + delete person.vehicles[1]; + delete person.vehicles[2]; + + person.should.deep.equal(expectedPerson, 'any object properties should not be overridden'); + }); + + it('should not add new properties to an object', function () { + person = freeze(person); + + person.occupation = 'Lawyer'; + person.nickname = 'JJ'; + + person.should.deep.equal(expectedPerson); + }); +});