-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(singleton-manager): add node/ssr support
- Loading branch information
Showing
7 changed files
with
63 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'singleton-manager': patch | ||
--- | ||
|
||
add node/ssr support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/singleton-manager/test-node/SingletonManagerClass.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { expect } from 'chai'; | ||
import { runSingletonManagerClassSuite } from '../test-suites/runSingletonManagerClassSuite.suite.js'; | ||
|
||
runSingletonManagerClassSuite({ expect }); |
39 changes: 39 additions & 0 deletions
39
packages/singleton-manager/test-suites/runSingletonManagerClassSuite.suite.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { SingletonManagerClass } from 'singleton-manager'; | ||
|
||
/** | ||
* @param {{expect: function}} config | ||
*/ | ||
export function runSingletonManagerClassSuite({ expect }) { | ||
describe('SingletonManagerClass', () => { | ||
it('returns undefined and has false if not set', async () => { | ||
const mngr = new SingletonManagerClass(); | ||
expect(mngr.get('overlays/overlays.js::0.13.x')).to.be.undefined; | ||
expect(mngr.has('overlays/overlays.js::0.13.x')).to.be.false; | ||
}); | ||
|
||
it('return value and has true if set', () => { | ||
const mngr = new SingletonManagerClass(); | ||
mngr.set('overlays/overlays.js::0.13.x', 'is-set'); | ||
expect(mngr.get('overlays/overlays.js::0.13.x')).to.equal('is-set'); | ||
expect(mngr.has('overlays/overlays.js::0.13.x')).to.be.true; | ||
// make sure non set values are still correct | ||
expect(mngr.get('overlays/overlays.js::0.14.x')).to.be.undefined; | ||
expect(mngr.has('overlays/overlays.js::0.14.x')).to.be.false; | ||
}); | ||
|
||
it('does not override existing keys (e.g. subsequential calls for the same keys are ignored)', () => { | ||
const mngr = new SingletonManagerClass(); | ||
mngr.set('overlays/overlays.js::0.14.x', 'is-set'); | ||
mngr.set('overlays/overlays.js::0.14.x', 'new-set'); | ||
expect(mngr.get('overlays/overlays.js::0.14.x')).to.equal('is-set'); | ||
}); | ||
|
||
it('should return the same value with two SingletonManager instances', () => { | ||
const mngr1 = new SingletonManagerClass(); | ||
const mngr2 = new SingletonManagerClass(); | ||
|
||
mngr1.set('overlays/overlays.js::0.15.x', 'is-set'); | ||
expect(mngr2.get('overlays/overlays.js::0.15.x')).to.equal('is-set'); | ||
}); | ||
}); | ||
} |
36 changes: 2 additions & 34 deletions
36
packages/singleton-manager/test/SingletonManagerClass.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,4 @@ | ||
import { expect } from '@open-wc/testing'; | ||
import { runSingletonManagerClassSuite } from '../test-suites/runSingletonManagerClassSuite.suite.js'; | ||
|
||
import { SingletonManagerClass } from 'singleton-manager'; | ||
|
||
describe('SingletonManagerClass', () => { | ||
it('returns undefined and has false if not set', async () => { | ||
const mngr = new SingletonManagerClass(); | ||
expect(mngr.get('overlays/overlays.js::0.13.x')).to.be.undefined; | ||
expect(mngr.has('overlays/overlays.js::0.13.x')).to.be.false; | ||
}); | ||
|
||
it('return value and has true if set', () => { | ||
const mngr = new SingletonManagerClass(); | ||
mngr.set('overlays/overlays.js::0.13.x', 'is-set'); | ||
expect(mngr.get('overlays/overlays.js::0.13.x')).to.equal('is-set'); | ||
expect(mngr.has('overlays/overlays.js::0.13.x')).to.be.true; | ||
// make sure non set values are still correct | ||
expect(mngr.get('overlays/overlays.js::0.14.x')).to.be.undefined; | ||
expect(mngr.has('overlays/overlays.js::0.14.x')).to.be.false; | ||
}); | ||
|
||
it('does not override existing keys (e.g. subsequential calls for the same keys are ignored)', () => { | ||
const mngr = new SingletonManagerClass(); | ||
mngr.set('overlays/overlays.js::0.14.x', 'is-set'); | ||
mngr.set('overlays/overlays.js::0.14.x', 'new-set'); | ||
expect(mngr.get('overlays/overlays.js::0.14.x')).to.equal('is-set'); | ||
}); | ||
|
||
it('should return the same value with two SingletonManager instances', () => { | ||
const mngr1 = new SingletonManagerClass(); | ||
const mngr2 = new SingletonManagerClass(); | ||
|
||
mngr1.set('overlays/overlays.js::0.15.x', 'is-set'); | ||
expect(mngr2.get('overlays/overlays.js::0.15.x')).to.equal('is-set'); | ||
}); | ||
}); | ||
runSingletonManagerClassSuite({ expect }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters