OverviewFilesCommitsIssuesDocsReleasesPeers

cthuloid / android / test / argv.test.js

23 lines · javascript ref:
// Where the worklet finds its storage. On the PHONE, bare-kit passes exactly the
// args the shell gives -- Bare.argv is [storage] (react-native-bare-kit
// shared/BareKitModule.cc: bare_worklet_start(..., args.size(), args)). On a
// desktop, `bare lib/worklet.js <storage>` puts the runtime and script first.
// 0.1.0 required argv.length > 1 and so never started on a phone.
import test from 'brittle'
import { storageFromArgv } from '../lib/argv.js'

const SELF = '/x/android/lib/worklet.js'

test('phone: the only argument is the storage dir', (t) => {
  t.is(storageFromArgv(['/data/user/0/org.circusautomatic.cthuloid/files'], SELF), '/data/user/0/org.circusautomatic.cthuloid/files')
})

test('desktop: runtime, script, storage', (t) => {
  t.is(storageFromArgv(['bare', SELF, '/tmp/s'], SELF), '/tmp/s')
})

test('desktop with no storage given: do not start', (t) => {
  t.is(storageFromArgv(['bare', SELF], SELF), null)
  t.is(storageFromArgv([], SELF), null)
})