-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file-entry-cache - fixing bug on save meta.data and changed state #904
Merged
jaredwray
merged 1 commit into
main
from
file-entry-cache---fixing-bug-on-save-meta.data-and-changed-state
Nov 23, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import path from 'node:path'; | |
import { | ||
describe, test, expect, beforeAll, afterAll, beforeEach, afterEach, | ||
} from 'vitest'; | ||
import defaultFileEntryCache, {FileEntryCache, type FileEntryCacheOptions} from '../src/index.js'; | ||
import defaultFileEntryCache, {createFromFile, FileEntryCache, type FileEntryCacheOptions} from '../src/index.js'; | ||
|
||
describe('file-entry-cache with options', () => { | ||
test('should initialize', () => { | ||
|
@@ -140,6 +140,7 @@ describe('getFileDescriptor()', () => { | |
const fileCacheName = '.cacheGFD'; | ||
beforeEach(() => { | ||
// Generate files for testing | ||
fs.rmSync(path.resolve(`./${fileCacheName}`), {recursive: true, force: true}); | ||
fs.mkdirSync(path.resolve(`./${fileCacheName}`)); | ||
fs.writeFileSync(path.resolve(`./${fileCacheName}/test1.txt`), 'test'); | ||
fs.writeFileSync(path.resolve(`./${fileCacheName}/test2.txt`), 'test sdfljsdlfjsdflsj'); | ||
|
@@ -160,6 +161,36 @@ describe('getFileDescriptor()', () => { | |
expect(fileDescriptor.meta.data).to.not.toBeDefined(); | ||
}); | ||
|
||
test('should save the meta data after the first call and loading data', () => { | ||
const shared = {shared: 'shared'}; | ||
const data = {testingFooVariable: '11', name: 'test1.txt', shared}; | ||
const fileEntryCache = new FileEntryCache({useCheckSum: true}); | ||
const testFile1 = path.resolve('./.cacheGFD/test1.txt'); | ||
const fileDescriptor = fileEntryCache.getFileDescriptor(testFile1); | ||
fileDescriptor.meta.data = data; | ||
expect(fileDescriptor).toBeDefined(); | ||
fileEntryCache.reconcile(); | ||
|
||
// Add the meta data to the cache | ||
const fileEntryCache2 = createFromFile(fileEntryCache.cache.cacheFilePath, true); | ||
const fileDescriptor2 = fileEntryCache2.getFileDescriptor(testFile1); | ||
const data2 = {testingFooVariable: '22', name: 'test1.txt', shared}; | ||
fileDescriptor2.meta.data = data2; | ||
fileEntryCache2.reconcile(); | ||
|
||
// Load the meta data from the cache | ||
const fileEntryCache3 = createFromFile(fileEntryCache.cache.cacheFilePath, true); | ||
const fileDescriptor3 = fileEntryCache3.getFileDescriptor(testFile1); | ||
expect(fileDescriptor3).toBeDefined(); | ||
expect(fileDescriptor3.meta.data).toEqual(data2); | ||
|
||
// Verify that the data shows changed | ||
const fileDescriptor4 = fileEntryCache3.getFileDescriptor(testFile1); | ||
expect(fileDescriptor4).toBeDefined(); | ||
expect(fileDescriptor4.meta.data).toEqual(data2); | ||
expect(fileDescriptor4.changed).toEqual(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you expect The file didn't change. Yes, In my case, I only care if the file changed, not the |
||
}); | ||
|
||
test('should return a file descriptor', () => { | ||
const fileEntryCache = new FileEntryCache(); | ||
const testFile1 = path.resolve('./.cacheGFD/test1.txt'); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.meta.data
is alwaysundefined
. It is caused by line 262.