UNPKG

@moonlightos/moonlight-hard

Version:

A way for open source developers to get paid

68 lines (58 loc) 1.74 kB
import test from 'ava' const util = require('../src/util') const { isAbsolute } = require('path') const { existsSync } = require('fs') test('install identifier works', t => { // test remove identifier && get identifier util.removeIdentifier() let id = util.getIdentifier() t.is(id, '') // test should show ad let show = util.shouldShowAd() t.true(show) // test set ad shown util.setAdShown('abc') id = util.getIdentifier() t.is(id, 'abc') // test should show ad show = util.shouldShowAd() t.false(show) // clear check file util.removeIdentifier() }) test('get sandbox path works', t => { const path = util.getSandboxPath() // check that path is absolute t.true(isAbsolute(path)) // check that file exists t.true(existsSync(path)) }) test.cb('opening browser works', t => { util.openBrowser('https://google.com', false, (success, error) => { t.end(error) }) }) test.cb('sandbox works', t => { const repository = 'repository_not_defined' const identifier = 'false_identifier' const url = util.config.AD_PATH + repository + '/' + identifier util.openBrowser(url, true, function (success, error) { if (success) { t.end(error) } else { t.end('Please click the "continue installation" button in order for the test to pass.') } }) }) test('generating install identifier works', t => { const identifier = util.generateIdentifier() // identifier is string t.is(typeof identifier, 'string') // identifier correct length t.is(identifier.length, 32) // identifier only letters and numbers t.true(/^[A-Za-z0-9]+$/.test(identifier)) }) test('fractional impressions', t => { t.true(util.fractionalImpression('repository_not_defined', 'npm')) })