adapt-authoring-core 1.9.0 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,6 @@
6
6
 
7
7
  > Handy guides and how-to information to help understand and make use of the Adapt authoring tool APIs in a practical way.
8
8
 
9
- [<i class="material-icons">download</i> Install](install)
9
+ [<i class="material-icons">download</i> Install](install-update-run)
10
10
  [<i class="material-icons">settings</i> Configure](configuration)
11
11
  [<i class="material-icons">flight_takeoff</i> Run](run)
@@ -74,6 +74,7 @@ class AbstractModule {
74
74
  if (!error) {
75
75
  this._isReady = true
76
76
  }
77
+ /** @ignore */ this._initError = error
77
78
  this.initTime = Math.round((Date.now() - this._startTime))
78
79
  this.log('verbose', AbstractModule.MODULE_READY, this.initTime)
79
80
  await this.readyHook.invoke(error)
@@ -86,7 +87,10 @@ class AbstractModule {
86
87
  async onReady () {
87
88
  return new Promise((resolve, reject) => {
88
89
  if (this._isReady) {
89
- return this._initError ? reject(this._initError) : resolve(this)
90
+ return resolve(this)
91
+ }
92
+ if (this._initError) {
93
+ return reject(this._initError)
90
94
  }
91
95
  this.readyHook.tap(error => {
92
96
  /** @ignore */this._initError = error
package/lib/Hook.js CHANGED
@@ -58,7 +58,7 @@ class Hook {
58
58
  * @returns Promise
59
59
  */
60
60
  onInvoke () {
61
- return new Promise((resolve, reject) => this._hookObservers.push([resolve, reject]))
61
+ return new Promise((resolve, reject) => this._promiseObservers.push([resolve, reject]))
62
62
  }
63
63
 
64
64
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-core",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "A bundle of reusable 'core' functionality",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-core",
6
6
  "license": "GPL-3.0",
@@ -455,11 +455,6 @@ describe('DependencyLoader', () => {
455
455
  assert.equal(result, mockInstance)
456
456
  })
457
457
 
458
- // TODO: Bug - Hook.onInvoke() pushes [resolve, reject] to _hookObservers where
459
- // invoke() tries to call it as a function, causing TypeError. The _promiseObservers
460
- // array that should handle these promises is never populated. This means
461
- // waitForModule() hangs when called before configs are loaded.
462
-
463
458
  it('should resolve via moduleLoadedHook when module not yet loaded', async () => {
464
459
  const mockApp = { rootDir: '/test' }
465
460
  const loader = new DependencyLoader(mockApp)
@@ -342,12 +342,6 @@ describe('Hook', () => {
342
342
  assert.deepEqual(arr, [1, 2, 3])
343
343
  })
344
344
  })
345
-
346
- // TODO: Bug - onInvoke() pushes a [resolve, reject] array to _hookObservers.
347
- // When invoke() runs, it tries to call this array as a function, which throws
348
- // TypeError. The promise returned by onInvoke() is never resolved or rejected
349
- // because _promiseObservers is never populated. This makes onInvoke() unusable
350
- // with invoke() - the onInvoke promise will hang forever.
351
345
  })
352
346
 
353
347
  describe('#onInvoke()', () => {
@@ -357,17 +351,17 @@ describe('Hook', () => {
357
351
  assert.ok(result instanceof Promise)
358
352
  })
359
353
 
360
- it('should add an entry to hook observers', () => {
354
+ it('should add an entry to promise observers', () => {
361
355
  const hook = new Hook()
362
- assert.equal(hook.hasObservers, false)
356
+ assert.equal(hook._promiseObservers.length, 0)
363
357
  hook.onInvoke()
364
- assert.equal(hook.hasObservers, true)
358
+ assert.equal(hook._promiseObservers.length, 1)
365
359
  })
366
360
 
367
- it('should add a resolve/reject pair as observer', () => {
361
+ it('should add a resolve/reject pair as promise observer', () => {
368
362
  const hook = new Hook()
369
363
  hook.onInvoke()
370
- const observer = hook._hookObservers[0]
364
+ const observer = hook._promiseObservers[0]
371
365
  assert.ok(Array.isArray(observer))
372
366
  assert.equal(observer.length, 2)
373
367
  })