| import { beforeEach, expect, it, jest } from '@jest/globals'; |
| import ScriptRunner from './ScriptRunner'; |
| interface FakeScriptOptions { |
| class FakeScript extends Script { |
| page: ScriptPage.CommunityConsole; |
| environment: ScriptEnvironment.ContentScript; |
| runPhase: ScriptRunPhase.Main; |
| constructor(options: FakeScriptOptions) { |
| this.priority = options.priority; |
| const fakeScriptMock = jest |
| .spyOn(FakeScript.prototype, 'execute') |
| .mockImplementation(function() { |
| return (this as FakeScript).id; |
| it('scripts run in the correct order based on priority', () => { |
| const scriptRunner = new ScriptRunner(); |
| scriptRunner.add(...scriptsConfig.map((config) => config.script)); |
| expect(fakeScriptMock).toHaveBeenCalledTimes(scriptsConfig.length); |
| for (const config of scriptsConfig) { |
| expect(fakeScriptMock).toHaveNthReturnedWith( |
| config.expectedRunPosition, |