-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make sure virtual configs do not appear as source files (#5048)
- Loading branch information
Showing
26 changed files
with
636 additions
and
47 deletions.
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
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
49 changes: 49 additions & 0 deletions
49
packages/cspell-config-lib/src/CSpellConfigFile/CSpellConfigFileJavaScript.test.ts
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { CSpellSettings } from '@cspell/cspell-types'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { CSpellConfigFileJavaScript } from './CSpellConfigFileJavaScript.js'; | ||
|
||
describe('CSpellConfigFileJavaScript', () => { | ||
const url = new URL('https://example.com/config'); | ||
const settings: CSpellSettings = {}; | ||
|
||
test('should create an instance of CSpellConfigFileInMemory', () => { | ||
const configFile = new CSpellConfigFileJavaScript(url, settings); | ||
expect(configFile).toBeInstanceOf(CSpellConfigFileJavaScript); | ||
}); | ||
|
||
test('should have the correct URL', () => { | ||
const configFile = new CSpellConfigFileJavaScript(url, settings); | ||
expect(configFile.url).toEqual(url); | ||
}); | ||
|
||
test('should have the correct settings', () => { | ||
const configFile = new CSpellConfigFileJavaScript(url, settings); | ||
expect(configFile.settings).toEqual(settings); | ||
}); | ||
|
||
test('should be readonly', () => { | ||
const configFile = new CSpellConfigFileJavaScript(url, settings); | ||
expect(configFile.readonly).toBe(true); | ||
}); | ||
|
||
test('should NOT be remote', () => { | ||
const configFile = new CSpellConfigFileJavaScript(new URL(import.meta.url), settings); | ||
expect(configFile.remote).toBe(false); | ||
}); | ||
|
||
test('should be remote', () => { | ||
const configFile = new CSpellConfigFileJavaScript(url, settings); | ||
expect(configFile.remote).toBe(true); | ||
}); | ||
|
||
test('should NOT be virtual', () => { | ||
const configFile = new CSpellConfigFileJavaScript(url, settings); | ||
expect(configFile.virtual).toBe(false); | ||
}); | ||
|
||
test('should throw when adding words', () => { | ||
const configFile = new CSpellConfigFileJavaScript(url, settings); | ||
expect(() => configFile.addWords(['word'])).toThrowError('Unable to add words to a JavaScript config file.'); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
packages/cspell-config-lib/src/CSpellConfigFile/CSpellConfigFileJson.test.ts
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { createTextFile } from '../TextFile.js'; | ||
import { CSpellConfigFileJson } from './CSpellConfigFileJson.js'; | ||
|
||
describe('CSpellConfigFileJson', () => { | ||
const url = new URL('https://example.com/config.json'); | ||
const settings = { | ||
language: 'en', | ||
ignoreWords: ['foo', 'bar'], | ||
}; | ||
|
||
test('should serialize the settings to JSON', () => { | ||
const configFile = new CSpellConfigFileJson(url, settings); | ||
const serialized = configFile.serialize(); | ||
expect(JSON.parse(serialized)).toEqual(settings); | ||
}); | ||
|
||
test('should serialize and preserve indent', () => { | ||
const content = JSON.stringify(settings, undefined, '\t') + '\n'; | ||
const configFile = CSpellConfigFileJson.parse({ url, content }); | ||
const serialized = configFile.serialize(); | ||
expect(serialized).toEqual(content); | ||
}); | ||
|
||
test('should parse a JSON file into CSpellConfigFileJson object', () => { | ||
const json = `{ | ||
// This is a comment | ||
"language": "en", | ||
"ignoreWords": ["foo", "bar"] | ||
}`; | ||
const file = createTextFile(url, json); | ||
const configFile = CSpellConfigFileJson.parse(file); | ||
expect(configFile.url).toEqual(url); | ||
expect(configFile.settings).toEqual(settings); | ||
|
||
const serialized = configFile.serialize(); | ||
expect(serialized).toEqual(expect.stringContaining('// This is a comment')); | ||
}); | ||
|
||
test('should throw an error when parsing an invalid JSON file', () => { | ||
const json = `{ | ||
"language": "en", | ||
"ignoreWords": ["foo", "bar" | ||
}`; | ||
const file = createTextFile(url, json); | ||
expect(() => CSpellConfigFileJson.parse(file)).toThrowError(); | ||
}); | ||
}); |
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
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
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
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
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
Oops, something went wrong.