step-definitions-module.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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);
  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.id),
  17. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  18. );
  19. assert.deepStrictEqual(
  20. steps.map((step) => step.key),
  21. [
  22. 'open-chatgpt',
  23. 'submit-signup-email',
  24. 'fill-password',
  25. 'fetch-signup-code',
  26. 'fill-profile',
  27. 'get-plus-link',
  28. 'fill-stripe-checkout',
  29. 'fill-paypal-login',
  30. 'fill-paypal-payment',
  31. 'sync-cpa-session',
  32. ]
  33. );
  34. });
  35. test('sidepanel html loads shared step definitions before sidepanel bootstrap', () => {
  36. const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8');
  37. const definitionsIndex = html.indexOf('<script src="../data/step-definitions.js"></script>');
  38. const sidepanelIndex = html.indexOf('<script src="sidepanel.js"></script>');
  39. assert.notEqual(definitionsIndex, -1);
  40. assert.notEqual(sidepanelIndex, -1);
  41. assert.ok(definitionsIndex < sidepanelIndex);
  42. });