eyeleng 1.2.0 → 1.2.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.
@@ -44,6 +44,27 @@ test('playground inline scripts are syntactically valid', () => {
44
44
  assert.ok(checked > 0, 'expected at least one inline playground script');
45
45
  });
46
46
 
47
+ test('playground embedded API exposes proof formatting', () => {
48
+ const html = fs.readFileSync(path.join(root, 'playground.html'), 'utf8');
49
+ const scripts = Array.from(html.matchAll(/<script(?<attrs>[^>]*)>(?<source>[\s\S]*?)<\/script>/g));
50
+ const bundleScript = scripts.find((match) => /__EYELENG_MODULES__/.test(match.groups.source));
51
+ assert.ok(bundleScript, 'expected an embedded playground API bundle');
52
+ const context = vm.createContext({ window: {} });
53
+ vm.runInContext(bundleScript.groups.source, context);
54
+ const modules = context.window.__EYELENG_MODULES__;
55
+ const mappings = context.window.__EYELENG_MAPPINGS__;
56
+ const cache = {};
57
+ function requireModule(id) {
58
+ if (cache[id]) return cache[id].exports;
59
+ const module = { exports: {} };
60
+ cache[id] = module;
61
+ const localRequire = (request) => requireModule((mappings[id] && mappings[id][request]) || request);
62
+ new Function('require', 'module', 'exports', modules[id])(localRequire, module, module.exports);
63
+ return module.exports;
64
+ }
65
+ assert.equal(typeof requireModule('src/api.js').formatProof, 'function');
66
+ });
67
+
47
68
 
48
69
  test('playground loads version from package.json at runtime', () => {
49
70
  const html = fs.readFileSync(path.join(root, 'playground.html'), 'utf8');
@@ -52,4 +73,11 @@ test('playground loads version from package.json at runtime', () => {
52
73
  assert.match(html, /id=["']version-label["'][^>]*>v…<\/span>/);
53
74
  });
54
75
 
76
+ test('Pages landing page renders the root README', () => {
77
+ const html = fs.readFileSync(path.join(root, 'index.html'), 'utf8');
78
+ assert.match(html, /fetch\(['"]README\.md['"]\)/);
79
+ assert.match(html, /marked\.parse\(markdown\)/);
80
+ assert.match(html, /class=["']markdown-body["']/);
81
+ });
82
+
55
83
  main();
package/tools/bundle.js CHANGED
@@ -151,6 +151,41 @@ function buildBrowser() {
151
151
  writeFile(browserOutput, chunks);
152
152
  }
153
153
 
154
+ function updatePlaygroundBundle() {
155
+ const { modules, mappings } = collectGraph('src/api.js');
156
+ const fallbackNames = [
157
+ 'family.srl',
158
+ 'socrates.srl',
159
+ 'spec-2-2-recursion.srl',
160
+ 'bmi.srl',
161
+ 'stratified-negation.srl',
162
+ 'spec-builtins.srl',
163
+ 'spec-4-2-rdf-rules-syntax.ttl',
164
+ 'basic-ruleset.ttl',
165
+ ];
166
+ const examples = {};
167
+ for (const name of fallbackNames) {
168
+ examples[name] = fs.readFileSync(path.join(root, 'examples', name), 'utf8');
169
+ }
170
+
171
+ const filename = path.join(root, playgroundOutput);
172
+ let html = fs.readFileSync(filename, 'utf8');
173
+ html = html.replace(
174
+ /^ window\.__EYELENG_MODULES__ = .*;$/m,
175
+ () => ` window.__EYELENG_MODULES__ = ${js(Object.fromEntries(modules.entries()))};`,
176
+ );
177
+ html = html.replace(
178
+ /^ window\.__EYELENG_MAPPINGS__ = .*;$/m,
179
+ () => ` window.__EYELENG_MAPPINGS__ = ${js(Object.fromEntries(mappings.entries()))};`,
180
+ );
181
+ html = html.replace(
182
+ /^ window\.__EYELENG_EXAMPLES__ = .*;$/m,
183
+ () => ` window.__EYELENG_EXAMPLES__ = ${js(examples)};`,
184
+ );
185
+ fs.writeFileSync(filename, html, 'utf8');
186
+ console.log(`updated ${playgroundOutput}`);
187
+ }
188
+
154
189
  function indent(source, spaces) {
155
190
  const prefix = ' '.repeat(spaces);
156
191
  return source.split('\n').map((line) => prefix + line).join('\n');
@@ -158,3 +193,4 @@ function indent(source, spaces) {
158
193
 
159
194
  buildCli();
160
195
  buildBrowser();
196
+ updatePlaygroundBundle();