Move Incremental Cache into class

This commit is contained in:
Sam Carlton 2021-06-26 12:56:49 -05:00
parent aa960903de
commit 12326c5b74
2 changed files with 124 additions and 42 deletions

View file

@ -1,15 +1,33 @@
import path from 'path'
import test from 'ava'
import { isObject, isString } from '../type-checks.js'
import {
getNetlifyConfig,
hasCachedPublishFolder,
cachePublishFolder,
CACHE_PATH
CACHE_PATH,
IncrementalCache
} from './caching.js'
test('Can read netlify.toml', async (t) => {
// Keeps tests from messing up production publish folder and files
const testingCachePath = path.join( CACHE_PATH, 'test' )
test.before(async t => {
t.context.cache = new IncrementalCache({
cachePath: testingCachePath
})
// Set up cache
await t.context.cache.init()
})
test.serial('Can read netlify.toml', async (t) => {
t.plan(2)
const netlifyConfig = await getNetlifyConfig()
@ -21,12 +39,17 @@ test('Can read netlify.toml', async (t) => {
})
test('Can cache publish folder', async (t) => {
test.serial('Can cache publish folder', async (t) => {
const {
cache
} = t.context
// So that we don't overwrite the cached files
// we check if a cached file already exists
if ( await hasCachedPublishFolder() ) {
t.log(`Found cached publish folder at ${ CACHE_PATH }`)
if ( await cache.hasCachedPublishFolder() ) {
t.log(`Found cached publish folder at ${ testingCachePath }`)
t.pass()
return
@ -37,15 +60,46 @@ test('Can cache publish folder', async (t) => {
// If there's no files there already
// then we can write to the directory with
await cachePublishFolder()
await cache.cachePublishFolder()
if ( (await hasCachedPublishFolder()) === false ) {
if ( (await cache.hasCachedPublishFolder()) === false ) {
t.fail()
return
}
t.log(`Cached publish folder at ${ CACHE_PATH }`)
t.log(`Cached publish folder at ${ testingCachePath }`)
t.pass()
})
test.serial('Can restore publish folder from cache', async (t) => {
const {
cache
} = t.context
if ( (await cache.hasCachedPublishFolder( testingCachePath )) === false ) {
t.log(`Could not find publish folder at ${ testingCachePath }`)
t.fail()
return
}
// await cache.emptyPublishDirectory()
// t.log('No prexisting cache folder found')
// // If there's no files there already
// // then we can write to the directory with
await cache.cachePublishFolder()
// t.log(`Cached publish folder at ${ testingCachePath }`)
t.pass()
})