adapt-authoring-adaptframework 2.5.6 → 3.0.0
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.
- package/.github/workflows/releases.yml +2 -1
- package/conf/config.schema.json +5 -0
- package/index.js +1 -1
- package/lib/AdaptFrameworkBuild.js +97 -47
- package/lib/AdaptFrameworkImport.js +87 -80
- package/lib/AdaptFrameworkModule.js +87 -4
- package/lib/BuildCache.js +105 -0
- package/lib/handlers.js +3 -2
- package/lib/migrations/vanilla-background-styles.js +17 -0
- package/lib/utils/applyBuildReplacements.js +23 -0
- package/lib/utils/collectMigrationScripts.js +15 -0
- package/lib/utils/computePluginHash.js +14 -0
- package/lib/utils/copyFrameworkSource.js +2 -2
- package/lib/utils/generateLanguageManifest.js +9 -0
- package/lib/utils/log.js +5 -7
- package/lib/utils/migrateExistingCourses.js +87 -0
- package/lib/utils/prebuildCache.js +110 -0
- package/lib/utils/readFrameworkPluginVersions.js +21 -0
- package/lib/utils/runContentMigration.js +72 -0
- package/lib/utils.js +8 -0
- package/package.json +4 -5
- package/tests/AdaptFrameworkImport.spec.js +7 -13
- package/tests/BuildCache.spec.js +107 -0
- package/tests/utils-applyBuildReplacements.spec.js +57 -0
- package/tests/utils-collectMigrationScripts.spec.js +45 -0
- package/tests/utils-computePluginHash.spec.js +40 -0
- package/tests/utils-generateLanguageManifest.spec.js +27 -0
- package/tests/utils-migrateExistingCourses.spec.js +163 -0
- package/tests/utils-readFrameworkPluginVersions.spec.js +48 -0
- package/tests/utils-runContentMigration.spec.js +101 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, it, mock } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
|
|
7
|
+
const testCachePath = fs.mkdtempSync(path.join(os.tmpdir(), 'runContentMigration-test-'))
|
|
8
|
+
|
|
9
|
+
const mockLoad = mock.fn(async () => {})
|
|
10
|
+
const mockMigrate = mock.fn(async ({ journal }) => {
|
|
11
|
+
journal.data.content[0].title = 'migrated'
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
class FakeJournal {
|
|
15
|
+
constructor ({ data }) {
|
|
16
|
+
this.data = data
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class FakeLogger {
|
|
21
|
+
info () {}
|
|
22
|
+
error () {}
|
|
23
|
+
warn () {}
|
|
24
|
+
debug () {}
|
|
25
|
+
log () {}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
mock.module('adapt-migrations', {
|
|
29
|
+
namedExports: {
|
|
30
|
+
load: mockLoad,
|
|
31
|
+
migrate: mockMigrate,
|
|
32
|
+
Journal: FakeJournal,
|
|
33
|
+
Logger: { getInstance: () => new FakeLogger() }
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const { runContentMigration } = await import('../lib/utils/runContentMigration.js')
|
|
38
|
+
|
|
39
|
+
describe('runContentMigration()', () => {
|
|
40
|
+
it('should call load with scripts and logger', async () => {
|
|
41
|
+
mockLoad.mock.resetCalls()
|
|
42
|
+
const scripts = ['/path/to/migration.js']
|
|
43
|
+
await runContentMigration({
|
|
44
|
+
content: [{ _id: 'c1', title: 'old' }],
|
|
45
|
+
fromPlugins: [{ name: 'core', version: '1.0.0' }],
|
|
46
|
+
toPlugins: [{ name: 'core', version: '2.0.0' }],
|
|
47
|
+
scripts,
|
|
48
|
+
cachePath: testCachePath
|
|
49
|
+
})
|
|
50
|
+
assert.equal(mockLoad.mock.calls.length, 1)
|
|
51
|
+
assert.deepEqual(mockLoad.mock.calls[0].arguments[0].scripts, scripts)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should create a Journal with correct data shape', async () => {
|
|
55
|
+
mockMigrate.mock.resetCalls()
|
|
56
|
+
await runContentMigration({
|
|
57
|
+
content: [{ _id: 'c1', title: 'old' }],
|
|
58
|
+
fromPlugins: [{ name: 'core', version: '1.0.0' }],
|
|
59
|
+
toPlugins: [{ name: 'core', version: '2.0.0' }],
|
|
60
|
+
scripts: [],
|
|
61
|
+
cachePath: testCachePath
|
|
62
|
+
})
|
|
63
|
+
assert.equal(mockMigrate.mock.calls.length, 1)
|
|
64
|
+
const journal = mockMigrate.mock.calls[0].arguments[0].journal
|
|
65
|
+
assert.ok(journal.data.content)
|
|
66
|
+
assert.ok(journal.data.fromPlugins)
|
|
67
|
+
assert.ok(journal.data.originalFromPlugins)
|
|
68
|
+
assert.ok(journal.data.toPlugins)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('should return mutated content', async () => {
|
|
72
|
+
mockMigrate.mock.resetCalls()
|
|
73
|
+
mockMigrate.mock.mockImplementation(async ({ journal }) => {
|
|
74
|
+
journal.data.content[0].title = 'migrated'
|
|
75
|
+
})
|
|
76
|
+
const result = await runContentMigration({
|
|
77
|
+
content: [{ _id: 'c1', title: 'old' }],
|
|
78
|
+
fromPlugins: [{ name: 'core', version: '1.0.0' }],
|
|
79
|
+
toPlugins: [{ name: 'core', version: '2.0.0' }],
|
|
80
|
+
scripts: [],
|
|
81
|
+
cachePath: testCachePath
|
|
82
|
+
})
|
|
83
|
+
assert.equal(result[0].title, 'migrated')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('should deep-clone fromPlugins into originalFromPlugins', async () => {
|
|
87
|
+
mockMigrate.mock.resetCalls()
|
|
88
|
+
mockMigrate.mock.mockImplementation(async () => {})
|
|
89
|
+
const fromPlugins = [{ name: 'core', version: '1.0.0' }]
|
|
90
|
+
await runContentMigration({
|
|
91
|
+
content: [{ _id: 'c1' }],
|
|
92
|
+
fromPlugins,
|
|
93
|
+
toPlugins: [{ name: 'core', version: '2.0.0' }],
|
|
94
|
+
scripts: [],
|
|
95
|
+
cachePath: testCachePath
|
|
96
|
+
})
|
|
97
|
+
const journal = mockMigrate.mock.calls[0].arguments[0].journal
|
|
98
|
+
assert.deepEqual(journal.data.originalFromPlugins, fromPlugins)
|
|
99
|
+
assert.notEqual(journal.data.originalFromPlugins, journal.data.fromPlugins)
|
|
100
|
+
})
|
|
101
|
+
})
|