import {expect} from "chai"

import {Factory} from "../../../../source/dom/worker/factory.mjs";
import {getGlobal} from "../../../../source/types/global.mjs";
import {initJSDOM, isNode} from "../../../util/jsdom.mjs";

const global = getGlobal();

describe('Worker', function () {

    before(function (done) {

        if (isNode()) {
            Object.defineProperty(global['URL'], 'createObjectURL', {
                writable: true,
                value: () => {
                    return "/example.mjs"
                }
            })

            global['Worker'] = class {
                terminate() {
                    
                }

                onerror() {
                    
                }

                onmessage() {
                    
                }
            }

            let a = typeof global['Worker'];
            let a1 = typeof Worker;

        }

        const jsdom = initJSDOM().then(() => {
            done();
        });


    })

    describe('Factory', function () {

        it('create worker', function () {

            const factory = new Factory();
            const worker = factory.createFromScript('console.log("hello world");')
            expect(worker).is.instanceof(Worker);

            expect(factory.terminate(worker)).is.instanceof(Factory)


        });

    });


});