mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Introduce NativeCompileCache
This commit is contained in:
1
spec/fixtures/native-cache/file-1.js
vendored
Normal file
1
spec/fixtures/native-cache/file-1.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = function () { return 1; }
|
||||
1
spec/fixtures/native-cache/file-2.js
vendored
Normal file
1
spec/fixtures/native-cache/file-2.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = function () { return 2; }
|
||||
37
spec/native-compile-cache-spec.coffee
Normal file
37
spec/native-compile-cache-spec.coffee
Normal file
@@ -0,0 +1,37 @@
|
||||
describe "NativeCompileCache", ->
|
||||
nativeCompileCache = require '../src/native-compile-cache'
|
||||
[fakeCacheStorage, cachedFiles] = []
|
||||
|
||||
beforeEach ->
|
||||
cachedFiles = []
|
||||
fakeCacheStorage = jasmine.createSpyObj("cache storage", ["set", "get"])
|
||||
nativeCompileCache.setCacheStorage(fakeCacheStorage)
|
||||
nativeCompileCache.install()
|
||||
|
||||
it "writes and reads from the cache storage when requiring files", ->
|
||||
fakeCacheStorage.get.andReturn(null)
|
||||
fakeCacheStorage.set.andCallFake (filename, cacheBuffer) ->
|
||||
cachedFiles.push({filename, cacheBuffer})
|
||||
|
||||
fn1 = require('./fixtures/native-cache/file-1')
|
||||
fn2 = require('./fixtures/native-cache/file-2')
|
||||
|
||||
expect(cachedFiles.length).toBe(2)
|
||||
|
||||
expect(cachedFiles[0].filename).toBe(require.resolve('./fixtures/native-cache/file-1'))
|
||||
expect(cachedFiles[0].cacheBuffer).toBeInstanceOf(Uint8Array)
|
||||
expect(cachedFiles[0].cacheBuffer.length).toBeGreaterThan(0)
|
||||
expect(fn1()).toBe(1)
|
||||
|
||||
expect(cachedFiles[1].filename).toBe(require.resolve('./fixtures/native-cache/file-2'))
|
||||
expect(cachedFiles[1].cacheBuffer).toBeInstanceOf(Uint8Array)
|
||||
expect(cachedFiles[1].cacheBuffer.length).toBeGreaterThan(0)
|
||||
expect(fn2()).toBe(2)
|
||||
|
||||
fakeCacheStorage.get.andReturn(cachedFiles[0].cacheBuffer)
|
||||
fakeCacheStorage.set.reset()
|
||||
|
||||
fn1 = require('./fixtures/native-cache/file-1')
|
||||
|
||||
expect(fakeCacheStorage.set).not.toHaveBeenCalled()
|
||||
expect(fn1()).toBe(1)
|
||||
Reference in New Issue
Block a user