|
1 | | -import {describe, expect, it} from 'vitest' |
2 | | - |
3 | | -import Service from '../src/index.js' |
| 1 | +import {Bud, factory} from '@repo/test-kit' |
| 2 | +import Cache from '@roots/bud-cache/service' |
| 3 | +import {Service} from '@roots/bud-framework/service' |
| 4 | +import {beforeEach, describe, expect, it} from 'vitest' |
4 | 5 |
|
5 | 6 | describe(`@roots/bud-cache`, () => { |
6 | | - it(`should be constructable`, () => { |
7 | | - expect(Service).toBeInstanceOf(Function) |
| 7 | + let bud: Bud |
| 8 | + let cache: Cache |
| 9 | + |
| 10 | + beforeEach(async () => { |
| 11 | + bud = await factory({cache: true}) |
| 12 | + cache = new Cache(() => bud) |
| 13 | + }) |
| 14 | + |
| 15 | + it(`should be a Service`, async () => { |
| 16 | + expect(cache).toBeInstanceOf(Service) |
| 17 | + }) |
| 18 | + |
| 19 | + it(`should have a boot method`, async () => { |
| 20 | + expect(cache.boot).toBeDefined() |
| 21 | + expect(cache.boot).toBeInstanceOf(Function) |
| 22 | + }) |
| 23 | + |
| 24 | + it(`should have a register method`, async () => { |
| 25 | + expect(cache.register).toBeDefined() |
| 26 | + expect(cache.register).toBeInstanceOf(Function) |
| 27 | + }) |
| 28 | + |
| 29 | + |
| 30 | + it(`should have a buildDependencies accessor interface`, async () => { |
| 31 | + expect(cache.buildDependencies).toBeDefined() |
| 32 | + expect(cache.buildDependencies).toBeInstanceOf(Object) |
| 33 | + }) |
| 34 | + |
| 35 | + it(`should have a cacheDirectory accessor interface`, async () => { |
| 36 | + await cache.register?.(bud) |
| 37 | + await cache.boot?.(bud) |
| 38 | + expect(cache.cacheDirectory).toBeDefined() |
| 39 | + expect(cache.cacheDirectory).toMatch(/@tests\/project\/cache$/) |
| 40 | + }) |
| 41 | + |
| 42 | + it(`should have a configuration getter`, async () => { |
| 43 | + await cache.register?.(bud) |
| 44 | + await cache.boot?.(bud) |
| 45 | + expect(cache.configuration).toBeDefined() |
| 46 | + expect(cache.configuration).toMatchInlineSnapshot(` |
| 47 | + { |
| 48 | + "allowCollectingMemory": true, |
| 49 | + "buildDependencies": { |
| 50 | + "bud": [ |
| 51 | + "${bud.path()}/package.json", |
| 52 | + "${bud.path()}/config/bud.config.js", |
| 53 | + ], |
| 54 | + "tailwind": [ |
| 55 | + "${bud.path()}/config/tailwind.config.js", |
| 56 | + ], |
| 57 | + }, |
| 58 | + "cacheDirectory": "${bud.context.paths?.[`os-cache`]}/@tests/project/cache", |
| 59 | + "compression": "brotli", |
| 60 | + "hashAlgorithm": "xxhash64", |
| 61 | + "idleTimeout": 100, |
| 62 | + "idleTimeoutForInitialStore": 0, |
| 63 | + "managedPaths": [ |
| 64 | + "${bud.context.paths?.[`os-cache`]}/@tests/project/cache", |
| 65 | + "${bud.path()}/node_modules", |
| 66 | + ], |
| 67 | + "name": "production", |
| 68 | + "profile": false, |
| 69 | + "store": "pack", |
| 70 | + "type": "filesystem", |
| 71 | + } |
| 72 | + `) |
8 | 73 | }) |
9 | 74 | }) |
0 commit comments