background-step1-cleanup.test.js 904 B

1234567891011121314151617181920212223242526272829303132
  1. const test = require('node:test');
  2. const assert = require('node:assert/strict');
  3. const fs = require('node:fs');
  4. const source = fs.readFileSync('background/steps/open-chatgpt.js', 'utf8');
  5. const globalScope = {};
  6. const api = new Function('self', `${source}; return self.MultiPageBackgroundStep1;`)(globalScope);
  7. test('step 1 clears login state before opening signup entry tab', async () => {
  8. const calls = [];
  9. const executor = api.createStep1Executor({
  10. addLog: async () => {},
  11. completeStepFromBackground: async () => {
  12. calls.push('complete');
  13. },
  14. openSignupEntryTab: async (_step, options) => {
  15. calls.push(['open', options]);
  16. },
  17. runPreStep1SessionCleanup: async () => {
  18. calls.push('cleanup');
  19. },
  20. });
  21. await executor.executeStep1();
  22. assert.deepStrictEqual(calls, [
  23. 'cleanup',
  24. ['open', { reloadIfSameUrl: true }],
  25. 'complete',
  26. ]);
  27. });