-
-
Notifications
You must be signed in to change notification settings - Fork 284
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
Extracts config.json into its own module #1061
Open
Spoffy
wants to merge
15
commits into
main
Choose a base branch
from
spoffy/elevate-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
abfbf20
Extracts FlexServer settings into a config module
Spoffy 7f2fbb4
Adds comment about untrustedContentRoot not being used
Spoffy 5837de1
WIP - Type checked config file.
Spoffy 7032e7c
Splits config into separate files
Spoffy 4e3ff70
Fixes various typing issues
Spoffy a8091f8
Makes config initialise when file not found
Spoffy 7592540
Moved config load into main()
Spoffy d84761b
Removes error handling in getGlobalConfig
Spoffy fbef8ca
Adds non-async config loader and unified memory/file/defaults
Spoffy 7c70a84
Cleans up some linter complaints
Spoffy 7be4383
Renames `loadLoginSystem` to `addLoginMiddleware`
Spoffy 1cf0178
Renames 'login' to 'loginMiddleware' FlexServer dep
Spoffy 66b3f71
Makes import formatting consistent
Spoffy f1498e4
Adds tests for config.ts
Spoffy 9276595
Adds configCore and configCoreFileFormats tests
Spoffy 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
Prev
Previous commit
Adds configCore and configCoreFileFormats tests
- Loading branch information
commit 9276595d9b118b285a3d8bbf190c1fb36acfc89d
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as sinon from 'sinon'; | ||
import { assert } from 'chai'; | ||
import { loadGristCoreConfig, loadGristCoreConfigFile } from "app/server/lib/configCore"; | ||
import { Deps } from "app/server/lib/config"; | ||
|
||
describe('loadGristCoreConfig', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('can be used with an in-memory store if no file config is provided', async () => { | ||
const config = loadGristCoreConfig(); | ||
await config.edition.set("enterprise"); | ||
assert.equal(config.edition.get(), "enterprise"); | ||
}); | ||
|
||
it('will function correctly when no config file is present', async () => { | ||
sinon.replace(Deps, 'pathExists', sinon.fake.resolves(false)); | ||
sinon.replace(Deps, 'readFile', sinon.fake.resolves("")); | ||
const writeFileFake = sinon.fake.resolves(undefined); | ||
sinon.replace(Deps, 'writeFile', writeFileFake); | ||
|
||
const config = await loadGristCoreConfigFile("doesntmatter.json"); | ||
assert.exists(config.edition.get()); | ||
|
||
await config.edition.set("enterprise"); | ||
// Make sure that the change was written back to the file. | ||
assert.isTrue(writeFileFake.calledOnce); | ||
}); | ||
}); |
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,29 @@ | ||
import { assert } from 'chai'; | ||
import { convertToCoreFileContents, IGristCoreConfigFileLatest } from "app/server/lib/configCoreFileFormats"; | ||
|
||
describe('convertToCoreFileContents', () => { | ||
it('fails with a malformed config', async () => { | ||
const badConfig = { | ||
version: "This is a random version number that will never exist", | ||
}; | ||
|
||
assert.isNull(convertToCoreFileContents(badConfig)); | ||
}); | ||
|
||
// This is necessary to handle users who don't have a config file yet. | ||
it('will upgrade an empty object to a valid config', () => { | ||
const validConfig = convertToCoreFileContents({}); | ||
assert.exists(validConfig?.version); | ||
}); | ||
|
||
it('will validate the latest config file format', () => { | ||
const validRawObject: IGristCoreConfigFileLatest = { | ||
version: "1", | ||
edition: "enterprise", | ||
}; | ||
|
||
const validConfig = convertToCoreFileContents(validRawObject); | ||
assert.exists(validConfig?.version); | ||
assert.exists(validConfig?.edition); | ||
}); | ||
}); |
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.
Can you put the imports in alphabetical order, and keep the quoting locally consistent. If you know I'm going to review, it can be a good idea to pre-review your own code for my import foibles: alphabetical, and consistent.
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.
Can do! I'm stuck in bad habits, too used to having a linter around that auto-formats all this! 😆