extwee 2.3.3 → 2.3.5

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 (41) hide show
  1. package/build/extwee.core.min.js +1 -1
  2. package/build/extwee.twine1html.min.js +1 -1
  3. package/build/extwee.twine2archive.min.js +1 -1
  4. package/build/extwee.tws.min.js +1 -1
  5. package/docs/build/extwee.core.min.js +1 -0
  6. package/docs/build/extwee.twine1html.min.js +1 -0
  7. package/docs/build/extwee.twine2archive.min.js +1 -0
  8. package/docs/build/extwee.tws.min.js +1 -0
  9. package/docs/demos/compiler/extwee.core.min.js +1 -0
  10. package/docs/demos/compiler/index.css +105 -0
  11. package/docs/demos/compiler/index.html +359 -0
  12. package/package.json +19 -18
  13. package/src/CLI/CommandLineProcessing.js +148 -153
  14. package/src/Passage.js +6 -4
  15. package/src/Story.js +1 -1
  16. package/src/Twee/parse.js +117 -21
  17. package/src/Twine2HTML/parse-web.js +7 -1
  18. package/src/Web/web-core.js +22 -2
  19. package/src/Web/web-twine1html.js +25 -5
  20. package/src/Web/web-twine2archive.js +25 -5
  21. package/src/Web/web-tws.js +22 -4
  22. package/test/Objects/Passage.test.js +1 -1
  23. package/test/Twee/Twee.Escaping.test.js +200 -0
  24. package/test/Twine1HTML/Twine1HTML.Parse.Web.test.js +484 -0
  25. package/test/Twine2ArchiveHTML/Twine2ArchiveHTML.Parse.Web.test.js +293 -0
  26. package/test/Twine2HTML/Twine2HTML.Parse.Web.test.js +329 -0
  27. package/test/Web/web-core-coverage.test.js +175 -0
  28. package/test/Web/web-core-global.test.js +93 -0
  29. package/test/Web/web-core.test.js +156 -0
  30. package/test/Web/web-twine1html.test.js +105 -0
  31. package/test/Web/web-twine2archive.test.js +96 -0
  32. package/test/Web/web-tws.test.js +77 -0
  33. package/test/Web/window.Extwee.test.js +7 -2
  34. package/types/src/Story.d.ts +1 -1
  35. package/types/src/Twee/parse.d.ts +21 -0
  36. package/types/src/Web/web-core.d.ts +23 -1
  37. package/types/src/Web/web-twine1html.d.ts +7 -0
  38. package/types/src/Web/web-twine2archive.d.ts +7 -0
  39. package/types/src/Web/web-tws.d.ts +5 -0
  40. package/webpack.config.js +2 -1
  41. package/src/Web/web-index.js +0 -31
@@ -0,0 +1,175 @@
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
+ });
@@ -0,0 +1,93 @@
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
+ });
@@ -0,0 +1,156 @@
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
+ });
@@ -0,0 +1,105 @@
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
+ });
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ /**
6
+ * Tests for web-twine2archive.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-twine2archive.js';
14
+ import Extwee from '../../src/Web/web-twine2archive.js';
15
+
16
+ describe('web-twine2archive.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 parseTwine2ArchiveHTML and compileTwine2ArchiveHTML', () => {
27
+ expect(Extwee.parseTwine2ArchiveHTML).toBeDefined();
28
+ expect(Extwee.compileTwine2ArchiveHTML).toBeDefined();
29
+ expect(Extwee.parse).toBeDefined();
30
+ expect(Extwee.compile).toBeDefined();
31
+ expect(typeof Extwee.parseTwine2ArchiveHTML).toBe('function');
32
+ expect(typeof Extwee.compileTwine2ArchiveHTML).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.parseTwine2ArchiveHTML).toBeDefined();
41
+ expect(globalThis.Extwee.compileTwine2ArchiveHTML).toBeDefined();
42
+ expect(typeof globalThis.Extwee.parseTwine2ArchiveHTML).toBe('function');
43
+ expect(typeof globalThis.Extwee.compileTwine2ArchiveHTML).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.parseTwine2ArchiveHTML).toBeDefined();
52
+ expect(globalThis.Extwee.compileTwine2ArchiveHTML).toBeDefined();
53
+ });
54
+ });
55
+
56
+ describe('Functional integration tests', () => {
57
+ it('should have working parseTwine2ArchiveHTML function', () => {
58
+ // Test with valid Twine 2 Archive HTML
59
+ const sampleHtml = `
60
+ <tw-storydata name="Test" startnode="1" creator="Twine" creator-version="2.3.5">
61
+ <tw-passagedata pid="1" name="Start" tags="">Start passage</tw-passagedata>
62
+ </tw-storydata>
63
+ `;
64
+
65
+ expect(() => {
66
+ const result = parse(sampleHtml);
67
+ expect(result).toBeDefined();
68
+ expect(Array.isArray(result)).toBe(true);
69
+ }).not.toThrow();
70
+ });
71
+
72
+ it('should have working compileTwine2ArchiveHTML function', async () => {
73
+ // Import required classes
74
+ const { Story } = await import('../../src/Story.js');
75
+ const { default: Passage } = await import('../../src/Passage.js');
76
+
77
+ const story = new Story();
78
+ story.name = "Test Story";
79
+ story.IFID = "12345678-1234-5678-9012-123456789012";
80
+ story.addPassage(new Passage("Start", "This is the start", [], {}));
81
+
82
+ expect(() => {
83
+ const result = compile([story]);
84
+ expect(typeof result).toBe('string');
85
+ }).not.toThrow();
86
+ });
87
+
88
+ it('should have same functions in exports and global', () => {
89
+ // Test that parse and compile are the same functions
90
+ expect(parse).toBe(Extwee.parse);
91
+ expect(compile).toBe(Extwee.compile);
92
+ expect(parse).toBe(Extwee.parseTwine2ArchiveHTML);
93
+ expect(compile).toBe(Extwee.compileTwine2ArchiveHTML);
94
+ });
95
+ });
96
+ });