{"size": 1624, "ext": "js", "max_stars_repo_path": "tests/load-scripts-in-namespaces.test.js", "max_stars_repo_name": "oussama-taoufiq/commones", "max_stars_repo_stars_event_min_datetime": "2020-05-21T05:49:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-21T07:53:00.000Z", "max_issues_repo_path": "tests/load-scripts-in-namespaces.test.js", "max_issues_repo_name": "oussama-taoufiq/commones", "max_issues_repo_issues_event_min_datetime": "2021-05-11T14:33:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T14:33:44.000Z", "max_forks_repo_path": "tests/load-scripts-in-namespaces.test.js", "max_forks_repo_name": "oussama-taoufiq/commones", "max_forks_repo_forks_event_min_datetime": "2020-05-21T05:55:15.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-21T06:56:14.000Z"}
{"max_stars_count": 5, "max_issues_count": 1, "max_forks_count": 2, "avg_line_length": 28.4912280702, "max_line_length": 98, "alphanum_fraction": 0.5714285714}
'use strict';

const puppeteer = require('puppeteer')

describe("The commonES instance can load various script in their own namespaces ...", () => {
    let browser
    let page

    beforeAll(async () => {
        browser = await puppeteer.launch({
            headless: true
        })

        page = await browser.newPage()
        await page.goto(
            "http://localhost:3000/index.html",
            {
                timeout: 10000,
                waitUntil: ["load", "domcontentloaded", "networkidle0"]
            }
        )
    })

    afterAll(async () => {
        browser.close()
    })

    test("Loading the Bar class in the nightclub namespace", async () => {
        await page.evaluate(() => {
            return commonES.ns('nightclub').require("./classes/Bar.js", 'Blob')
        })

        await page.waitFor(3000)

        // Checking for the Bar class in the nightclub namespace.
        let barClassName = await page.evaluate(() => {
            return (new nightclub.Blob()).constructor.name
        })

        expect(barClassName).toBe('Bar')

        // Checking for the Foo class aliases as Banana in the _ namespace.
        let bananaClassName = await page.evaluate(() => {
            return (new _.Banana()).constructor.name
        })

        expect(bananaClassName).toBe('Foo')

        // Checking for the Foo class aliases as Orange in the com_abdoulaye_playground namespace.
        let orangeClassName = await page.evaluate(() => {
            return (new com_abdoulaye_playground.Orange()).constructor.name
        })

        expect(orangeClassName).toBe('Foo')
    })
})
