step-definitions-module.test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const test = require('node:test');
  2. const assert = require('node:assert/strict');
  3. const fs = require('node:fs');
  4. test('step definitions module exposes ordered shared step metadata', () => {
  5. const source = fs.readFileSync('data/step-definitions.js', 'utf8');
  6. const globalScope = {};
  7. const api = new Function('self', `${source}; return self.MultiPageStepDefinitions;`)(globalScope);
  8. const steps = api.getSteps();
  9. assert.equal(Array.isArray(steps), true);
  10. assert.equal(steps.length >= 10, true);
  11. assert.deepStrictEqual(
  12. steps.map((step) => step.order),
  13. steps.map((step) => step.order).slice().sort((left, right) => left - right)
  14. );
  15. assert.deepStrictEqual(
  16. steps.map((step) => step.key),
  17. [
  18. 'open-chatgpt',
  19. 'submit-signup-email',
  20. 'fill-password',
  21. 'fetch-signup-code',
  22. 'fill-profile',
  23. 'clear-login-cookies',
  24. 'oauth-login',
  25. 'fetch-login-code',
  26. 'confirm-oauth',
  27. 'platform-verify',
  28. ]
  29. );
  30. });
  31. test('sidepanel html loads shared step definitions before sidepanel bootstrap', () => {
  32. const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8');
  33. const definitionsIndex = html.indexOf('<script src="../data/step-definitions.js"></script>');
  34. const sidepanelIndex = html.indexOf('<script src="sidepanel.js"></script>');
  35. assert.notEqual(definitionsIndex, -1);
  36. assert.notEqual(sidepanelIndex, -1);
  37. assert.ok(definitionsIndex < sidepanelIndex);
  38. });