import { __awaiter, __generator } from "tslib";
import { mocked } from 'ts-jest/utils';
import { JSDOM } from 'jsdom';
import { AnalyticsBrowser } from '../../../browser';
jest.mock('unfetch', function () {
    return jest.fn();
});
import unfetch from 'unfetch';
describe.skip('Remote Plugin Integration', function () {
    var window = global.window;
    beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
        var html, jsd, windowSpy, cdnResponse;
        return __generator(this, function (_a) {
            jest.restoreAllMocks();
            jest.resetAllMocks();
            html = "\n    <!DOCTYPE html>\n      <head>\n        <script>'hi'</script>\n      </head>\n      <body>\n      </body>\n    </html>\n    ".trim();
            jsd = new JSDOM(html, {
                runScripts: 'dangerously',
                resources: 'usable',
                url: 'https://localhost',
            });
            windowSpy = jest.spyOn(global, 'window', 'get');
            windowSpy.mockImplementation(function () { return jsd.window; });
            cdnResponse = {
                integrations: {},
                remotePlugins: [
                    // This may be a bit flaky
                    // we should mock this file in case it becomes a problem
                    // but I'd like to have a full integration test if possible
                    {
                        url: 'https://ajs-next-integrations.s3-us-west-2.amazonaws.com/fab-5/amplitude-plugins.js',
                        libraryName: 'amplitude-pluginsDestination',
                        settings: {
                            subscriptions: "[{\"partnerAction\":\"sessionId\",\"name\":\"SessionId\",\"enabled\":true,\"subscribe\":\"type = \\\"track\\\"\", \"mapping\":{}}]",
                        },
                    },
                ],
            };
            // @ts-ignore mocking fetch is *hard*
            mocked(unfetch).mockImplementation(function () {
                // @ts-expect-error
                return Promise.resolve({
                    json: function () { return Promise.resolve(cdnResponse); },
                });
            });
            return [2 /*return*/];
        });
    }); });
    it('loads remote plugins', function () { return __awaiter(void 0, void 0, void 0, function () {
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, AnalyticsBrowser.load({
                        writeKey: 'test-write-key',
                    })
                    // loaded remote plugin
                ];
                case 1:
                    _a.sent();
                    // loaded remote plugin
                    expect(window['amplitude-pluginsDestination']).not.toBeUndefined();
                    return [2 /*return*/];
            }
        });
    }); });
});
//# sourceMappingURL=integration.test.js.map