extwee 2.3.10 → 2.3.12

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.
Files changed (180) hide show
  1. package/CHANGELOG.md +219 -0
  2. package/CONTRIBUTING.md +305 -0
  3. package/README.md +16 -0
  4. package/build/extwee.core.min.js +1 -1
  5. package/build/extwee.twine1html.min.js +1 -1
  6. package/build/extwee.twine2archive.min.js +1 -1
  7. package/build/extwee.tws.min.js +1 -1
  8. package/package.json +8 -5
  9. package/src/Passage.js +8 -9
  10. package/src/Story.js +2 -2
  11. package/types/src/Story.d.ts +1 -1
  12. package/.github/FUNDING.yml +0 -3
  13. package/.github/codeql-analysis.yml +0 -51
  14. package/.github/dependabot.yml +0 -11
  15. package/.github/workflows/dependabot-automerge.yml +0 -23
  16. package/.github/workflows/nodejs.yml +0 -28
  17. package/.travis.yml +0 -13
  18. package/babel.config.json +0 -18
  19. package/docs/.nojekyll +0 -0
  20. package/docs/README.md +0 -224
  21. package/docs/_sidebar.md +0 -19
  22. package/docs/build/extwee.core.min.js +0 -1
  23. package/docs/build/extwee.twine1html.min.js +0 -1
  24. package/docs/build/extwee.twine2archive.min.js +0 -1
  25. package/docs/build/extwee.tws.min.js +0 -1
  26. package/docs/demos/compiler/extwee.core.min.js +0 -1
  27. package/docs/demos/compiler/index.css +0 -105
  28. package/docs/demos/compiler/index.html +0 -359
  29. package/docs/demos/decompile/extwee.core.min.js +0 -1
  30. package/docs/demos/decompile/index.css +0 -584
  31. package/docs/demos/decompile/index.html +0 -468
  32. package/docs/examples/dynamicPassages.md +0 -28
  33. package/docs/examples/jsonToTwee.md +0 -23
  34. package/docs/examples/twsToTwee.md +0 -25
  35. package/docs/formats/json.md +0 -17
  36. package/docs/formats/twee.md +0 -13
  37. package/docs/formats/twine1HTML.md +0 -13
  38. package/docs/formats/twine2ArchiveHTML.md +0 -13
  39. package/docs/formats/twine2HTML.md +0 -13
  40. package/docs/formats/tws.md +0 -9
  41. package/docs/index.html +0 -26
  42. package/docs/install/npm.md +0 -16
  43. package/docs/install/npx.md +0 -79
  44. package/docs/objects/passage.md +0 -47
  45. package/docs/objects/story.md +0 -69
  46. package/docs/objects/storyformat.md +0 -27
  47. package/eslint.config.js +0 -28
  48. package/extwee.config.json +0 -6
  49. package/extwee.config.md +0 -67
  50. package/jest.config.json +0 -5
  51. package/test/CLI/CLI.test.js +0 -49
  52. package/test/CLI/files/example.json +0 -1
  53. package/test/CLI/files/example6.twee +0 -22
  54. package/test/CLI/files/harlowe.js +0 -3
  55. package/test/CLI/files/input.html +0 -47
  56. package/test/CLI/files/output/test.twee +0 -0
  57. package/test/CLI/files/test.twee +0 -18
  58. package/test/CLI/files/tweeExample.twee +0 -17
  59. package/test/CLI/files/twine1/LICENSE.txt +0 -32
  60. package/test/CLI/files/twine1/code.js +0 -5
  61. package/test/CLI/files/twine1/engine.js +0 -43
  62. package/test/CLI/files/twine1/header.html +0 -325
  63. package/test/CLI/files/twine1Test.html +0 -371
  64. package/test/CLI/files/twineExample.html +0 -16
  65. package/test/Config/Config.test.js +0 -76
  66. package/test/Config/files/empty.json +0 -3
  67. package/test/Config/files/full.json +0 -8
  68. package/test/Config/files/invalid.json +0 -1
  69. package/test/Config/files/valid.json +0 -6
  70. package/test/Config/isDirectory.test.js +0 -50
  71. package/test/Config/isFile.test.js +0 -53
  72. package/test/Config/loadStoryFormat.test.js +0 -117
  73. package/test/Config/readDirectories.test.js +0 -78
  74. package/test/IFID/IFID.Generate.test.js +0 -10
  75. package/test/JSON/JSON.Parse.test.js +0 -316
  76. package/test/Objects/Passage.test.js +0 -270
  77. package/test/Objects/SnowmanCompatibility.test.js +0 -125
  78. package/test/Objects/Story.test.js +0 -1075
  79. package/test/Objects/StoryFormat.test.js +0 -219
  80. package/test/Roundtrip/Files/Example1.html +0 -64
  81. package/test/Roundtrip/Files/LICENSE +0 -19
  82. package/test/Roundtrip/Files/example1.twee +0 -10
  83. package/test/Roundtrip/Files/example2.twee +0 -27
  84. package/test/Roundtrip/Files/example4.twee +0 -27
  85. package/test/Roundtrip/Files/harlowe.js +0 -3
  86. package/test/Roundtrip/Files/round.html +0 -49
  87. package/test/Roundtrip/Roundtrip.test.js +0 -54
  88. package/test/StoryFormat/StoryFormat.Parse.test.js +0 -479
  89. package/test/TWS/Parse.test.js +0 -56
  90. package/test/TWS/TWSParser/Example5.tws +0 -414
  91. package/test/TWS/TWSParser/noscale.tws +0 -0
  92. package/test/TWS/TWSParser/nostory.tws +0 -0
  93. package/test/Twee/Twee.Escaping.test.js +0 -200
  94. package/test/Twee/Twee.Parse.test.js +0 -108
  95. package/test/Twee/TweeParser/cursed.twee +0 -16
  96. package/test/Twee/TweeParser/cycling.twee +0 -75
  97. package/test/Twee/TweeParser/emptytags.twee +0 -2
  98. package/test/Twee/TweeParser/example.twee +0 -32
  99. package/test/Twee/TweeParser/malformed.twee +0 -2
  100. package/test/Twee/TweeParser/missing.twee +0 -19
  101. package/test/Twee/TweeParser/multipleScriptPassages.twee +0 -19
  102. package/test/Twee/TweeParser/multipleStyleTag.twee +0 -19
  103. package/test/Twee/TweeParser/multipletags.twee +0 -10
  104. package/test/Twee/TweeParser/noTitle.twee +0 -2
  105. package/test/Twee/TweeParser/notes.twee +0 -16
  106. package/test/Twee/TweeParser/pasagemetadataerror.twee +0 -2
  107. package/test/Twee/TweeParser/scriptPassage.twee +0 -16
  108. package/test/Twee/TweeParser/singletag.twee +0 -13
  109. package/test/Twee/TweeParser/start.twee +0 -2
  110. package/test/Twee/TweeParser/startMetadata.twee +0 -14
  111. package/test/Twee/TweeParser/storydataerror.twee +0 -25
  112. package/test/Twee/TweeParser/style.twee +0 -16
  113. package/test/Twee/TweeParser/stylePassage.twee +0 -16
  114. package/test/Twee/TweeParser/test.twee +0 -25
  115. package/test/Twine1HTML/Twine1HTML.Compile.test.js +0 -180
  116. package/test/Twine1HTML/Twine1HTML.Parse.Web.test.js +0 -484
  117. package/test/Twine1HTML/Twine1HTML.Parse.test.js +0 -183
  118. package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/LICENSE +0 -674
  119. package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/engine.js +0 -43
  120. package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/jquery.js +0 -4
  121. package/test/Twine1HTML/Twine1HTMLCompiler/Twine1/modernizr.js +0 -4
  122. package/test/Twine1HTML/Twine1HTMLCompiler/engineTest.html +0 -1
  123. package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/LICENSE +0 -32
  124. package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/code.js +0 -4
  125. package/test/Twine1HTML/Twine1HTMLCompiler/jonah-1.4.2/header.html +0 -327
  126. package/test/Twine1HTML/Twine1HTMLCompiler/test.html +0 -0
  127. package/test/Twine1HTML/Twine1HTMLCompiler/test1.html +0 -6
  128. package/test/Twine1HTML/Twine1HTMLCompiler/test2.html +0 -6
  129. package/test/Twine1HTML/Twine1HTMLCompiler/test3.html +0 -43
  130. package/test/Twine1HTML/Twine1HTMLCompiler/test4.html +0 -372
  131. package/test/Twine1HTML/Twine1HTMLCompiler/test5.html +0 -372
  132. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Compile.test.js +0 -35
  133. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.Web.test.js +0 -293
  134. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.test.js +0 -42
  135. package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLCompiler/test1.html +0 -6
  136. package/test/Twine2ArchiveHTML/Twine2ArchiveHTMLParser/test1.html +0 -3
  137. package/test/Twine2HTML/Twine2HTML.Compile.test.js +0 -139
  138. package/test/Twine2HTML/Twine2HTML.Parse.Web.test.js +0 -329
  139. package/test/Twine2HTML/Twine2HTML.Parse.test.js +0 -192
  140. package/test/Twine2HTML/Twine2HTMLCompiler/TestTags.html +0 -42
  141. package/test/Twine2HTML/Twine2HTMLCompiler/creator.html +0 -50
  142. package/test/Twine2HTML/Twine2HTMLCompiler/example6.twee +0 -16
  143. package/test/Twine2HTML/Twine2HTMLCompiler/format.js +0 -9
  144. package/test/Twine2HTML/Twine2HTMLCompiler/missingStoryTitle.twee +0 -29
  145. package/test/Twine2HTML/Twine2HTMLCompiler/test11.html +0 -121
  146. package/test/Twine2HTML/Twine2HTMLCompiler/test2.html +0 -58
  147. package/test/Twine2HTML/Twine2HTMLCompiler/test3.html +0 -49
  148. package/test/Twine2HTML/Twine2HTMLCompiler/test4.html +0 -50
  149. package/test/Twine2HTML/Twine2HTMLCompiler/test6.html +0 -49
  150. package/test/Twine2HTML/Twine2HTMLParser/Example1.html +0 -53
  151. package/test/Twine2HTML/Twine2HTMLParser/Tags.html +0 -15
  152. package/test/Twine2HTML/Twine2HTMLParser/lyingStartnode.html +0 -15
  153. package/test/Twine2HTML/Twine2HTMLParser/lyingTagColors.html +0 -48
  154. package/test/Twine2HTML/Twine2HTMLParser/missingCreator.html +0 -11
  155. package/test/Twine2HTML/Twine2HTMLParser/missingCreatorVersion.html +0 -11
  156. package/test/Twine2HTML/Twine2HTMLParser/missingFormat.html +0 -11
  157. package/test/Twine2HTML/Twine2HTMLParser/missingFormatVersion.html +0 -11
  158. package/test/Twine2HTML/Twine2HTMLParser/missingIFID.html +0 -11
  159. package/test/Twine2HTML/Twine2HTMLParser/missingPassageTags.html +0 -15
  160. package/test/Twine2HTML/Twine2HTMLParser/missingPosition.html +0 -15
  161. package/test/Twine2HTML/Twine2HTMLParser/missingScript.html +0 -14
  162. package/test/Twine2HTML/Twine2HTMLParser/missingSize.html +0 -35
  163. package/test/Twine2HTML/Twine2HTMLParser/missingStartnode.html +0 -11
  164. package/test/Twine2HTML/Twine2HTMLParser/missingStyle.html +0 -14
  165. package/test/Twine2HTML/Twine2HTMLParser/missingZoom.html +0 -11
  166. package/test/Twine2HTML/Twine2HTMLParser/tagColors.html +0 -31
  167. package/test/Twine2HTML/Twine2HTMLParser/twineExample.html +0 -23
  168. package/test/Twine2HTML/Twine2HTMLParser/twineExample2.html +0 -15
  169. package/test/Twine2HTML/Twine2HTMLParser/twineExample3.html +0 -15
  170. package/test/Twine2HTML/Twine2HTMLParser/unescaping.html +0 -33
  171. package/test/Web/web-core-coverage.test.js +0 -175
  172. package/test/Web/web-core-global.test.js +0 -93
  173. package/test/Web/web-core.test.js +0 -156
  174. package/test/Web/web-exports.test.js +0 -136
  175. package/test/Web/web-twine1html.test.js +0 -105
  176. package/test/Web/web-twine2archive.test.js +0 -96
  177. package/test/Web/web-tws.test.js +0 -77
  178. package/test/Web/window.Extwee.test.js +0 -97
  179. package/tsconfig.json +0 -21
  180. package/webpack.config.js +0 -47
@@ -1,175 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- // Test the global object detection logic more comprehensively
6
- // by testing the function directly rather than trying to manipulate the environment
7
-
8
- describe('web-core.js comprehensive global detection coverage', () => {
9
-
10
- it('should test all branches of global object detection function', () => {
11
- // Recreate the exact global object detection logic from web-core.js
12
- const globalObjectDetectionFunction = function() {
13
- if (typeof globalThis !== 'undefined') return globalThis;
14
- if (typeof window !== 'undefined') return window;
15
- if (typeof global !== 'undefined') return global;
16
- if (typeof self !== 'undefined') return self;
17
- return null;
18
- };
19
-
20
- // Test the function logic
21
- const result = globalObjectDetectionFunction();
22
-
23
- // In Node.js environment, should return global
24
- expect(result).toBe(global);
25
-
26
- // Verify that global exists
27
- expect(typeof global).toBe('object');
28
- expect(global).toBeTruthy();
29
- });
30
-
31
- it('should test globalThis branch when globalThis is defined', () => {
32
- // Test what happens when globalThis is available
33
- const mockGlobalThisTest = function() {
34
- // Simulate having globalThis available
35
- const fakeGlobalThis = { type: 'globalThis' };
36
-
37
- // Mock the detection logic
38
- const detect = function(mockGlobalThis, mockWindow, mockGlobal, mockSelf) {
39
- if (typeof mockGlobalThis !== 'undefined' && mockGlobalThis !== null) return 'globalThis';
40
- if (typeof mockWindow !== 'undefined' && mockWindow !== null) return 'window';
41
- if (typeof mockGlobal !== 'undefined' && mockGlobal !== null) return 'global';
42
- if (typeof mockSelf !== 'undefined' && mockSelf !== null) return 'self';
43
- return 'null';
44
- };
45
-
46
- return detect(fakeGlobalThis, undefined, undefined, undefined);
47
- };
48
-
49
- expect(mockGlobalThisTest()).toBe('globalThis');
50
- });
51
-
52
- it('should test self branch when only self is available', () => {
53
- // Test what happens when only self is available (Web Worker scenario)
54
- const mockSelfTest = function() {
55
- const fakeSelf = { type: 'self' };
56
-
57
- const detect = function(mockGlobalThis, mockWindow, mockGlobal, mockSelf) {
58
- if (typeof mockGlobalThis !== 'undefined' && mockGlobalThis !== null) return 'globalThis';
59
- if (typeof mockWindow !== 'undefined' && mockWindow !== null) return 'window';
60
- if (typeof mockGlobal !== 'undefined' && mockGlobal !== null) return 'global';
61
- if (typeof mockSelf !== 'undefined' && mockSelf !== null) return 'self';
62
- return 'null';
63
- };
64
-
65
- return detect(undefined, undefined, undefined, fakeSelf);
66
- };
67
-
68
- expect(mockSelfTest()).toBe('self');
69
- });
70
-
71
- it('should test null return when no global objects are available', () => {
72
- // Test what happens when no global objects are available
73
- const mockNullTest = function() {
74
- const detect = function(mockGlobalThis, mockWindow, mockGlobal, mockSelf) {
75
- if (typeof mockGlobalThis !== 'undefined' && mockGlobalThis !== null) return 'globalThis';
76
- if (typeof mockWindow !== 'undefined' && mockWindow !== null) return 'window';
77
- if (typeof mockGlobal !== 'undefined' && mockGlobal !== null) return 'global';
78
- if (typeof mockSelf !== 'undefined' && mockSelf !== null) return 'self';
79
- return null;
80
- };
81
-
82
- return detect(undefined, undefined, undefined, undefined);
83
- };
84
-
85
- expect(mockNullTest()).toBeNull();
86
- });
87
-
88
- it('should test priority order of global object detection', () => {
89
- // Test that globalThis > window > global > self priority is maintained
90
- const mockPriorityTest = function() {
91
- const fakeGlobalThis = { type: 'globalThis' };
92
- const fakeWindow = { type: 'window' };
93
- const fakeGlobal = { type: 'global' };
94
- const fakeSelf = { type: 'self' };
95
-
96
- const detect = function(mockGlobalThis, mockWindow, mockGlobal, mockSelf) {
97
- if (typeof mockGlobalThis !== 'undefined' && mockGlobalThis !== null) return mockGlobalThis;
98
- if (typeof mockWindow !== 'undefined' && mockWindow !== null) return mockWindow;
99
- if (typeof mockGlobal !== 'undefined' && mockGlobal !== null) return mockGlobal;
100
- if (typeof mockSelf !== 'undefined' && mockSelf !== null) return mockSelf;
101
- return null;
102
- };
103
-
104
- // When all are available, should return globalThis
105
- const result1 = detect(fakeGlobalThis, fakeWindow, fakeGlobal, fakeSelf);
106
- expect(result1.type).toBe('globalThis');
107
-
108
- // When globalThis not available, should return window
109
- const result2 = detect(undefined, fakeWindow, fakeGlobal, fakeSelf);
110
- expect(result2.type).toBe('window');
111
-
112
- // When globalThis and window not available, should return global
113
- const result3 = detect(undefined, undefined, fakeGlobal, fakeSelf);
114
- expect(result3.type).toBe('global');
115
-
116
- // When only self available, should return self
117
- const result4 = detect(undefined, undefined, undefined, fakeSelf);
118
- expect(result4.type).toBe('self');
119
- };
120
-
121
- mockPriorityTest();
122
- });
123
-
124
- it('should verify that global object assignment logic works', () => {
125
- // Test the assignment logic without requiring module import
126
- const mockAssignmentScenario = function() {
127
- // Simulate Node.js environment where global is available
128
- const fakeGlobal = {};
129
- const fakeExtwee = { version: '2.3.3' };
130
-
131
- // Simulate the assignment from web-core.js
132
- if (fakeGlobal) {
133
- fakeGlobal.Extwee = fakeExtwee;
134
- }
135
-
136
- return fakeGlobal;
137
- };
138
-
139
- const result = mockAssignmentScenario();
140
- expect(result.Extwee).toBeDefined();
141
- expect(result.Extwee.version).toBe('2.3.3');
142
- });
143
-
144
- it('should test that assignment is conditional on globalObject being truthy', () => {
145
- // This tests the `if (globalObject)` condition in the web-core.js
146
- const mockAssignmentTest = function() {
147
- let assignmentCalled = false;
148
-
149
- const mockAssign = function(globalObj, extweeObj) {
150
- if (globalObj) {
151
- globalObj.Extwee = extweeObj;
152
- assignmentCalled = true;
153
- }
154
- };
155
-
156
- // Test with truthy global object
157
- const fakeGlobal = {};
158
- const fakeExtwee = { version: '2.3.3' };
159
- mockAssign(fakeGlobal, fakeExtwee);
160
-
161
- expect(assignmentCalled).toBe(true);
162
- expect(fakeGlobal.Extwee).toBe(fakeExtwee);
163
-
164
- // Test with null global object
165
- assignmentCalled = false;
166
- const fakeGlobal2 = {};
167
- mockAssign(null, fakeExtwee);
168
-
169
- expect(assignmentCalled).toBe(false);
170
- expect(fakeGlobal2.Extwee).toBeUndefined();
171
- };
172
-
173
- mockAssignmentTest();
174
- });
175
- });
@@ -1,93 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
- // Import the module to test global assignment in jsdom environment
6
- import '../../src/Web/web-core.js';
7
-
8
- describe('web-core.js global assignment in browser environment', () => {
9
- it('should assign Extwee to window in jsdom environment', () => {
10
- // Should have assigned to window automatically on import
11
- expect(window.Extwee).toBeDefined();
12
- expect(window.Extwee.version).toBe('2.3.3');
13
- expect(typeof window.Extwee).toBe('object');
14
- });
15
-
16
- it('should have all expected properties on window.Extwee', () => {
17
- expect(window.Extwee.parseTwee).toBeDefined();
18
- expect(window.Extwee.parseJSON).toBeDefined();
19
- expect(window.Extwee.parseStoryFormat).toBeDefined();
20
- expect(window.Extwee.parseTwine2HTML).toBeDefined();
21
- expect(window.Extwee.compileTwine2HTML).toBeDefined();
22
- expect(window.Extwee.generateIFID).toBeDefined();
23
- expect(window.Extwee.Story).toBeDefined();
24
- expect(window.Extwee.Passage).toBeDefined();
25
- expect(window.Extwee.StoryFormat).toBeDefined();
26
- });
27
-
28
- it('should verify global object detection logic ran (window branch)', () => {
29
- // This test verifies that the globalObject detection function found window
30
- // and assigned Extwee to it
31
- expect(typeof window).toBe('object');
32
- expect(window).not.toBeNull();
33
- expect(window.Extwee).toBeDefined();
34
- });
35
-
36
- it('should have working functions on window.Extwee', () => {
37
- // Test that the assigned functions work correctly
38
- const ifid = window.Extwee.generateIFID();
39
- expect(ifid).toMatch(/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/);
40
-
41
- const story = new window.Extwee.Story();
42
- expect(story).toBeDefined();
43
- expect(Array.isArray(story.passages)).toBe(true);
44
- });
45
-
46
- // Test to exercise the globalObject detection function
47
- it('should test global object detection function directly', () => {
48
- // This is a test to simulate what the global object detection function does
49
- // We can't easily mock the environment during module loading, but we can
50
- // verify the logic by recreating it
51
-
52
- const globalObjectDetectionLogic = function() {
53
- if (typeof globalThis !== 'undefined') return 'globalThis';
54
- if (typeof window !== 'undefined') return 'window';
55
- if (typeof global !== 'undefined') return 'global';
56
- if (typeof self !== 'undefined') return 'self';
57
- return null;
58
- };
59
-
60
- // In jsdom environment, could return 'globalThis' or 'window' depending on Node.js version
61
- const result = globalObjectDetectionLogic();
62
- expect(['globalThis', 'window']).toContain(result);
63
-
64
- // Verify window exists and is truthy
65
- expect(typeof window).toBe('object');
66
- expect(window).toBeTruthy();
67
- });
68
-
69
- // Test for globalThis availability (Modern browsers/Node.js 12+)
70
- it('should handle globalThis when available', () => {
71
- // Test the globalThis branch logic
72
- if (typeof globalThis !== 'undefined') {
73
- expect(globalThis).toBeDefined();
74
- expect(typeof globalThis).toBe('object');
75
-
76
- // In environments with globalThis, it should be preferred
77
- const mockGlobalDetection = function() {
78
- if (typeof globalThis !== 'undefined') return 'globalThis';
79
- if (typeof window !== 'undefined') return 'window';
80
- if (typeof global !== 'undefined') return 'global';
81
- if (typeof self !== 'undefined') return 'self';
82
- return null;
83
- };
84
-
85
- // Should prefer globalThis if available
86
- const detectionResult = mockGlobalDetection();
87
- expect(['globalThis', 'window']).toContain(detectionResult);
88
- } else {
89
- // If globalThis not available, should fall back to window in jsdom
90
- expect(typeof window).toBe('object');
91
- }
92
- });
93
- });
@@ -1,156 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- // Import to test basic functionality
6
- import { parseTwee, parseJSON, parseStoryFormat, parseTwine2HTML, compileTwine2HTML, generateIFID, Story, Passage, StoryFormat } from '../../src/Web/web-core.js';
7
- import Extwee from '../../src/Web/web-core.js';
8
-
9
- describe('web-core.js Node.js environment tests', () => {
10
- describe('ES6 module exports', () => {
11
- it('should export all individual functions and classes', () => {
12
- expect(parseTwee).toBeDefined();
13
- expect(typeof parseTwee).toBe('function');
14
-
15
- expect(parseJSON).toBeDefined();
16
- expect(typeof parseJSON).toBe('function');
17
-
18
- expect(parseStoryFormat).toBeDefined();
19
- expect(typeof parseStoryFormat).toBe('function');
20
-
21
- expect(parseTwine2HTML).toBeDefined();
22
- expect(typeof parseTwine2HTML).toBe('function');
23
-
24
- expect(compileTwine2HTML).toBeDefined();
25
- expect(typeof compileTwine2HTML).toBe('function');
26
-
27
- expect(generateIFID).toBeDefined();
28
- expect(typeof generateIFID).toBe('function');
29
-
30
- expect(Story).toBeDefined();
31
- expect(typeof Story).toBe('function');
32
-
33
- expect(Passage).toBeDefined();
34
- expect(typeof Passage).toBe('function');
35
-
36
- expect(StoryFormat).toBeDefined();
37
- expect(typeof StoryFormat).toBe('function');
38
- });
39
-
40
- it('should export default Extwee object with all properties', () => {
41
- expect(Extwee).toBeDefined();
42
- expect(typeof Extwee).toBe('object');
43
-
44
- expect(Extwee.parseTwee).toBeDefined();
45
- expect(Extwee.parseJSON).toBeDefined();
46
- expect(Extwee.parseStoryFormat).toBeDefined();
47
- expect(Extwee.parseTwine2HTML).toBeDefined();
48
- expect(Extwee.compileTwine2HTML).toBeDefined();
49
- expect(Extwee.generateIFID).toBeDefined();
50
- expect(Extwee.Story).toBeDefined();
51
- expect(Extwee.Passage).toBeDefined();
52
- expect(Extwee.StoryFormat).toBeDefined();
53
- expect(Extwee.version).toBe('2.3.3');
54
- });
55
-
56
- it('should have same functions in default export as individual exports', () => {
57
- expect(Extwee.parseTwee).toBe(parseTwee);
58
- expect(Extwee.parseJSON).toBe(parseJSON);
59
- expect(Extwee.parseStoryFormat).toBe(parseStoryFormat);
60
- expect(Extwee.parseTwine2HTML).toBe(parseTwine2HTML);
61
- expect(Extwee.compileTwine2HTML).toBe(compileTwine2HTML);
62
- expect(Extwee.generateIFID).toBe(generateIFID);
63
- expect(Extwee.Story).toBe(Story);
64
- expect(Extwee.Passage).toBe(Passage);
65
- expect(Extwee.StoryFormat).toBe(StoryFormat);
66
- });
67
- });
68
-
69
- describe('Functional integration tests', () => {
70
- it('should have working parseTwee function', () => {
71
- const tweeContent = `:: Start
72
- This is the start passage.`;
73
-
74
- const result = parseTwee(tweeContent);
75
- expect(result).toBeDefined();
76
- expect(result.passages).toBeDefined();
77
- expect(result.passages.length).toBe(1);
78
- expect(result.passages[0].name).toBe('Start');
79
- });
80
-
81
- it('should have working parseJSON function', () => {
82
- const jsonContent = JSON.stringify({
83
- passages: [{
84
- name: 'Start',
85
- text: 'This is the start passage.',
86
- tags: [],
87
- metadata: {}
88
- }],
89
- name: 'Test Story',
90
- IFID: '12345678-1234-5678-9012-123456789012'
91
- });
92
-
93
- const result = parseJSON(jsonContent);
94
- expect(result).toBeDefined();
95
- expect(result.passages).toBeDefined();
96
- expect(result.passages.length).toBe(1);
97
- expect(result.name).toBe('Test Story');
98
- });
99
-
100
- it('should have working generateIFID function', () => {
101
- const ifid = generateIFID();
102
- expect(ifid).toMatch(/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/);
103
- });
104
-
105
- it('should have working Story constructor', () => {
106
- const story = new Story();
107
- expect(story).toBeDefined();
108
- expect(story.passages).toBeDefined();
109
- expect(Array.isArray(story.passages)).toBe(true);
110
- });
111
-
112
- it('should have working Passage constructor', () => {
113
- const passage = new Passage();
114
- expect(passage).toBeDefined();
115
- expect(passage.name).toBeDefined();
116
- expect(passage.text).toBeDefined();
117
- expect(passage.tags).toBeDefined();
118
- expect(Array.isArray(passage.tags)).toBe(true);
119
- });
120
-
121
- it('should have working StoryFormat constructor', () => {
122
- const storyFormat = new StoryFormat();
123
- expect(storyFormat).toBeDefined();
124
- expect(storyFormat.name).toBeDefined();
125
- expect(storyFormat.version).toBeDefined();
126
- });
127
- });
128
-
129
- describe('Global assignment in Node.js environment', () => {
130
- it('should assign to global.global in Node.js environment', () => {
131
- // In Node.js environment, it should assign to global.global
132
- expect(global.global.Extwee).toBeDefined();
133
- expect(global.global.Extwee.version).toBe('2.3.3');
134
- expect(global.global.Extwee).toBe(Extwee);
135
- });
136
-
137
- it('should verify global object detection logic execution', () => {
138
- // This test ensures the global object detection function runs
139
- // In Node.js, typeof globalThis is 'undefined' (in older versions),
140
- // typeof window is 'undefined', typeof global is 'object', typeof self is 'undefined'
141
- expect(typeof global).toBe('object');
142
- expect(global.global).toBeDefined();
143
- });
144
- });
145
-
146
- describe('Version consistency', () => {
147
- it('should have consistent version across exports', () => {
148
- expect(Extwee.version).toBe('2.3.3');
149
- });
150
-
151
- it('should have version property as string', () => {
152
- expect(typeof Extwee.version).toBe('string');
153
- expect(Extwee.version.length).toBeGreaterThan(0);
154
- });
155
- });
156
- });
@@ -1,136 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- /**
6
- * Tests for package.json web exports
7
- * These tests verify that users can import the web builds directly
8
- */
9
-
10
- import { describe, expect, it } from '@jest/globals';
11
- import fs from 'node:fs';
12
- import path from 'node:path';
13
-
14
- describe('Web build exports', () => {
15
- const buildDir = path.resolve(process.cwd(), 'build');
16
-
17
- describe('Web build files exist', () => {
18
- it('should have core web build file', () => {
19
- const corePath = path.join(buildDir, 'extwee.core.min.js');
20
- expect(fs.existsSync(corePath)).toBe(true);
21
- });
22
-
23
- it('should have twine1html web build file', () => {
24
- const twine1Path = path.join(buildDir, 'extwee.twine1html.min.js');
25
- expect(fs.existsSync(twine1Path)).toBe(true);
26
- });
27
-
28
- it('should have twine2archive web build file', () => {
29
- const twine2ArchivePath = path.join(buildDir, 'extwee.twine2archive.min.js');
30
- expect(fs.existsSync(twine2ArchivePath)).toBe(true);
31
- });
32
-
33
- it('should have tws web build file', () => {
34
- const twsPath = path.join(buildDir, 'extwee.tws.min.js');
35
- expect(fs.existsSync(twsPath)).toBe(true);
36
- });
37
- });
38
-
39
- describe('Web build content validation', () => {
40
- it('should have UMD wrapper in core build', () => {
41
- const corePath = path.join(buildDir, 'extwee.core.min.js');
42
- const content = fs.readFileSync(corePath, 'utf8');
43
-
44
- // Should contain UMD pattern
45
- expect(content).toMatch(/function.*webpackUniversalModuleDefinition|define.*function|module\.exports.*function/);
46
-
47
- // Should be minified (no excessive whitespace)
48
- expect(content.split('\n').length).toBeLessThan(10);
49
- });
50
-
51
- it('should have Extwee functionality in core build', () => {
52
- const corePath = path.join(buildDir, 'extwee.core.min.js');
53
- const content = fs.readFileSync(corePath, 'utf8');
54
-
55
- // Should contain core Extwee functionality
56
- expect(content).toMatch(/parseTwee|parseJSON|generateIFID|Story/);
57
- });
58
-
59
- it('should have appropriate size for minified builds', () => {
60
- const corePath = path.join(buildDir, 'extwee.core.min.js');
61
- const stats = fs.statSync(corePath);
62
-
63
- // Core build should be substantial but not excessive (roughly 50-150KB)
64
- expect(stats.size).toBeGreaterThan(50000); // > 50KB
65
- expect(stats.size).toBeLessThan(150000); // < 150KB
66
- });
67
-
68
- it('should have smaller specialized builds', () => {
69
- const corePath = path.join(buildDir, 'extwee.core.min.js');
70
- const twine1Path = path.join(buildDir, 'extwee.twine1html.min.js');
71
- const coreStats = fs.statSync(corePath);
72
- const twine1Stats = fs.statSync(twine1Path);
73
-
74
- // Specialized builds should be smaller than core
75
- expect(twine1Stats.size).toBeLessThan(coreStats.size);
76
- });
77
- });
78
-
79
- describe('Package.json exports configuration', () => {
80
- it('should have exports field in package.json', () => {
81
- const packagePath = path.resolve(process.cwd(), 'package.json');
82
- const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
83
-
84
- expect(packageJson.exports).toBeDefined();
85
- expect(typeof packageJson.exports).toBe('object');
86
- });
87
-
88
- it('should have correct web export paths', () => {
89
- const packagePath = path.resolve(process.cwd(), 'package.json');
90
- const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
91
-
92
- expect(packageJson.exports['.']).toBe('./index.js');
93
- expect(packageJson.exports['./web']).toBe('./build/extwee.core.min.js');
94
- expect(packageJson.exports['./web/core']).toBe('./build/extwee.core.min.js');
95
- expect(packageJson.exports['./web/twine1html']).toBe('./build/extwee.twine1html.min.js');
96
- expect(packageJson.exports['./web/twine2archive']).toBe('./build/extwee.twine2archive.min.js');
97
- expect(packageJson.exports['./web/tws']).toBe('./build/extwee.tws.min.js');
98
- });
99
-
100
- it('should point to files that actually exist', () => {
101
- const packagePath = path.resolve(process.cwd(), 'package.json');
102
- const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
103
-
104
- // Check each web export path exists
105
- const webExports = [
106
- packageJson.exports['./web'],
107
- packageJson.exports['./web/core'],
108
- packageJson.exports['./web/twine1html'],
109
- packageJson.exports['./web/twine2archive'],
110
- packageJson.exports['./web/tws']
111
- ];
112
-
113
- for (const exportPath of webExports) {
114
- const fullPath = path.resolve(process.cwd(), exportPath);
115
- expect(fs.existsSync(fullPath)).toBe(true);
116
- }
117
- });
118
- });
119
-
120
- describe('Documentation for web exports', () => {
121
- it('should provide clear usage examples', () => {
122
- // This test documents how users can import the web builds
123
- const usageExamples = {
124
- 'import Extwee from "extwee/web"': 'Core web build with most functionality',
125
- 'import Extwee from "extwee/web/core"': 'Same as above (explicit)',
126
- 'import Extwee from "extwee/web/twine1html"': 'Twine 1 HTML parsing only',
127
- 'import Extwee from "extwee/web/twine2archive"': 'Twine 2 Archive HTML parsing only',
128
- 'import Extwee from "extwee/web/tws"': 'TWS (Twine 1 workspace) parsing only'
129
- };
130
-
131
- // Just verify we have documented the usage patterns
132
- expect(Object.keys(usageExamples)).toHaveLength(5);
133
- expect(usageExamples['import Extwee from "extwee/web"']).toContain('Core web build');
134
- });
135
- });
136
- });
@@ -1,105 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- /**
6
- * Tests for web-twine1html.js module
7
- * Tests module exports and functionality
8
- */
9
-
10
- import { describe, expect, it } from '@jest/globals';
11
-
12
- // Import to test basic functionality
13
- import { parse, compile } from '../../src/Web/web-twine1html.js';
14
- import Extwee from '../../src/Web/web-twine1html.js';
15
-
16
- describe('web-twine1html.js module tests', () => {
17
-
18
- describe('ES6 module exports', () => {
19
- it('should export parse and compile functions', () => {
20
- expect(parse).toBeDefined();
21
- expect(compile).toBeDefined();
22
- expect(typeof parse).toBe('function');
23
- expect(typeof compile).toBe('function');
24
- });
25
-
26
- it('should export default object with parseTwine1HTML and compileTwine1HTML', () => {
27
- expect(Extwee.parseTwine1HTML).toBeDefined();
28
- expect(Extwee.compileTwine1HTML).toBeDefined();
29
- expect(Extwee.parse).toBeDefined();
30
- expect(Extwee.compile).toBeDefined();
31
- expect(typeof Extwee.parseTwine1HTML).toBe('function');
32
- expect(typeof Extwee.compileTwine1HTML).toBe('function');
33
- });
34
- });
35
-
36
- describe('Global object assignment', () => {
37
- it('should assign functions to global object when available', () => {
38
- // In Node.js environment, should assign to globalThis
39
- expect(globalThis.Extwee).toBeDefined();
40
- expect(globalThis.Extwee.parseTwine1HTML).toBeDefined();
41
- expect(globalThis.Extwee.compileTwine1HTML).toBeDefined();
42
- expect(typeof globalThis.Extwee.parseTwine1HTML).toBe('function');
43
- expect(typeof globalThis.Extwee.compileTwine1HTML).toBe('function');
44
- });
45
-
46
- it('should preserve existing Extwee properties', () => {
47
- // Should not overwrite the entire object, just add properties
48
- if (globalThis.Extwee && globalThis.Extwee.version) {
49
- expect(globalThis.Extwee.version).toBeDefined();
50
- }
51
- expect(globalThis.Extwee.parseTwine1HTML).toBeDefined();
52
- expect(globalThis.Extwee.compileTwine1HTML).toBeDefined();
53
- });
54
- });
55
-
56
- describe('Functional integration tests', () => {
57
- it('should have working parseTwine1HTML function', () => {
58
- // Test with valid Twine 1 HTML
59
- const sampleHtml = `
60
- <html>
61
- <head><title>Test</title></head>
62
- <body>
63
- <div id="storeArea" data-size="2">
64
- <div tiddler="Start" tags="" twine-position="100,100">Start passage</div>
65
- </div>
66
- </body>
67
- </html>
68
- `;
69
-
70
- expect(() => {
71
- const result = parse(sampleHtml);
72
- expect(result).toBeDefined();
73
- expect(result.passages).toBeDefined();
74
- }).not.toThrow();
75
- });
76
-
77
- it('should have working compileTwine1HTML function', async () => {
78
- // Import required classes dynamically to avoid circular imports
79
- const { Story } = await import('../../src/Story.js');
80
- const { default: Passage } = await import('../../src/Passage.js');
81
- const { default: StoryFormat } = await import('../../src/StoryFormat.js');
82
-
83
- const story = new Story();
84
- story.name = "Test Story";
85
- story.addPassage(new Passage("Start", "This is the start", [], {}));
86
-
87
- const storyFormat = new StoryFormat();
88
- storyFormat.source = "window.story = STORY;";
89
- storyFormat.version = "1.0.0";
90
-
91
- expect(() => {
92
- const result = compile(story, storyFormat, '', '', '');
93
- expect(typeof result).toBe('string');
94
- }).not.toThrow();
95
- });
96
-
97
- it('should have same functions in exports and global', () => {
98
- // Test that parse and compile are the same functions
99
- expect(parse).toBe(Extwee.parse);
100
- expect(compile).toBe(Extwee.compile);
101
- expect(parse).toBe(Extwee.parseTwine1HTML);
102
- expect(compile).toBe(Extwee.compileTwine1HTML);
103
- });
104
- });
105
- });