lamed_io
Version:
68 lines (59 loc) • 2.56 kB
JavaScript
// Add module to test.runner.js
// 'use strict' // Comment out in test functions
console.log(`Starting ${__filename}...`) // comment line to remove simple logging
// ------------------------------------------------------
// localstorage.test.js
// Purpose: The purpose of this to test localstorage
// Date Created: 2020/01/28
// Created by : Perez Lamed van Niekerk
// ------------------------------------------------------
/* jshint esversion: 6 */
const { con, unZip, unThrow, isTestRunner } = require('lamed_test') // eslint-disable-line
const _lio = require('../src/lamed_io')
const _storage = new _lio.LocalStorage('./.appSettings')
// ---------------------------------------------------
// Setup unit test
const show = !isTestRunner()
if (show) {
con.traceSet(0) // Activate trace when not run from test runner
// con.useChalk(require('chalk')) // Give us some colour
}
con.logLine()
con.log(` --> ${__filename}`) // Show test case
con.traceLine()
con.trace(module.filename)
con.traceBold(`--------------------------> ${arguments.callee.name}()`) // eslint-disable-line
let error = `In ${module.filename} --> ${arguments.callee.name}()` // eslint-disable-line
var _setupEnv = _storage.Get('environment', 'JSN')
var _setupEnvName = _storage.Get('environmentName', '(Unknown)')
var _setupEnvGlobal = _storage.Get('environmentGlobal', true)
con.trace({ _setupEnv, _setupEnvName, _setupEnvGlobal })
con.traceLine()
const items0 = _storage.History()
con.trace({ items0 })
con.traceLine()
const path = _lio.rootFolder() + 'templates/'
// This opperation is very slow
// _storage.Push(path + 'asdfsadfasfassv1')
// _storage.Push(path + 'asdfsadfasfassv2')
// _storage.Push(path + 'asdfsadfasfassv3')
// _storage.Push(path + 'asdfsadfasfassv4')
// _storage.Push(path + 'asdfsadfasfassv5')
// _storage.Push(path + 'asdfsadfasfassv6')
// _storage.Push(path + 'asdfsadfasfassv7')
// _storage.Push(path + 'asdfsadfasfassv8')
// _storage.Push(path + 'asdfsadfasfassv7')
// _storage.Push(path + 'asdfsadfasfassv10')
_storage.Push(path + 'asdfsadfasfassv12')
_storage.Push(path + 'asdfsadfasfassv7')
_storage.Push('New item')
_storage.Push('New item2')
const items = _storage.History()
if (items[0] !== 'New item2') throw new Error(error)
if (items[1] !== 'New item') throw new Error(error)
unZip(() => _storage.HistoryItem(1), items[0])
unZip(() => _storage.HistoryItem('1'), items[0])
unZip(() => _storage.History()[0], items[0])
// ------------------------------------------------
con.logGreen(` √ ${__filename}`) // Success!!!
con.traceLine()