-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eas-cli] Add js metadata config file support (#1270)
* [eas-cli] Add js metadata config file support * [eas-cli] Add js metadata config file download support * update CHANGELOG.md * [eas-cli] Only save static files when pulling metadata * [eas-cli] Support config functions and async functions in metadata * [eas-cli] Tweak the metadata logs * [eas-cli] Improve the dynamic config return validation * [eas-cli] Apply improved language suggestions from the pros Co-authored-by: Dominik Sokal <dominik.sokal@swmansion.com> * [eas-cli] Apply code changes from review Co-authored-by: Dominik Sokal <dominik.sokal@swmansion.com> Co-authored-by: Wojciech Kozyra <wojciech.kozyra@swmansion.com> * [eas-cli] Split out load config logging and move validation to single method * [eas-cli] Fix missed renamed function Co-authored-by: Dominik Sokal <dominik.sokal@swmansion.com> Co-authored-by: Wojciech Kozyra <wojciech.kozyra@swmansion.com>
- Loading branch information
1 parent
c8935e1
commit faf1e90
Showing
18 changed files
with
290 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import path from 'path'; | ||
|
||
import { getStaticConfigFilePath, loadConfigAsync } from '../config'; | ||
import { MetadataValidationError } from '../errors'; | ||
|
||
describe(getStaticConfigFilePath, () => { | ||
const projectDir = '/app'; | ||
|
||
it(`returns same file for store.config.json`, () => { | ||
const metadataPath = 'store.config.json'; | ||
const expectedFile = path.join(projectDir, metadataPath); | ||
|
||
expect(getStaticConfigFilePath({ projectDir, metadataPath })).toBe(expectedFile); | ||
}); | ||
|
||
it(`returns store.config.json for store.config.js`, () => { | ||
const metadataPath = 'store.config.js'; | ||
const expectedFile = path.join(projectDir, 'store.config.json'); | ||
|
||
expect(getStaticConfigFilePath({ projectDir, metadataPath })).toBe(expectedFile); | ||
}); | ||
|
||
it(`returns store.staging.json file for store.staging.js`, () => { | ||
const metadataPath = 'store.staging.js'; | ||
const expectedFile = path.join(projectDir, 'store.staging.json'); | ||
|
||
expect(getStaticConfigFilePath({ projectDir, metadataPath })).toBe(expectedFile); | ||
}); | ||
|
||
// This shouldn't be used IRL, but it tests if this function is working properly | ||
it(`returns custom-name.json file for custom-name.js`, () => { | ||
const metadataPath = 'custom-name.js'; | ||
const expectedFile = path.join(projectDir, 'custom-name.json'); | ||
|
||
expect(getStaticConfigFilePath({ projectDir, metadataPath })).toBe(expectedFile); | ||
}); | ||
}); | ||
|
||
describe(loadConfigAsync, () => { | ||
const projectDir = path.resolve(__dirname, 'fixtures'); | ||
|
||
it(`throws when file doesn't exist`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'doesnt-exist.json' }) | ||
).rejects.toThrow('file not found'); | ||
}); | ||
|
||
it(`throws when validation errors are found without skipping validation`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid.config.json' }) | ||
).rejects.toThrow('errors found'); | ||
}); | ||
|
||
it(`returns config from "store.config.json"`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'store.config.json' }) | ||
).resolves.toHaveProperty('apple.copyright', 'ACME'); | ||
}); | ||
|
||
it(`returns config from "store.config.js"`, async () => { | ||
const year = new Date().getFullYear(); | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'store.config.js' }) | ||
).resolves.toHaveProperty('apple.copyright', `${year} ACME`); | ||
}); | ||
|
||
it(`returns config from "store.function.js"`, async () => { | ||
const year = new Date().getFullYear(); | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'store.function.js' }) | ||
).resolves.toHaveProperty('apple.copyright', `${year} ACME`); | ||
}); | ||
|
||
it(`returns config from "store.async.js"`, async () => { | ||
const year = new Date().getFullYear(); | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'store.async.js' }) | ||
).resolves.toHaveProperty('apple.copyright', `${year} ACME`); | ||
}); | ||
|
||
it(`returns invalid config from "invalid.config.json`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid.config.json', skipValidation: true }) | ||
).resolves.toMatchObject({ configVersion: -1 }); | ||
}); | ||
|
||
it(`returns invalid config from "invalid.config.js`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid.config.js', skipValidation: true }) | ||
).resolves.toMatchObject({ configVersion: -1 }); | ||
}); | ||
|
||
it(`returns invalid config from "invalid.function.js`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid.function.js', skipValidation: true }) | ||
).resolves.toMatchObject({ configVersion: -1 }); | ||
}); | ||
|
||
it(`returns invalid config from "invalid.async.js`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid.async.js', skipValidation: true }) | ||
).resolves.toMatchObject({ configVersion: -1 }); | ||
}); | ||
|
||
it(`throws invalid config type from "invalid-type.config.json"`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid-type.config.json' }) | ||
).rejects.toThrow(MetadataValidationError); | ||
}); | ||
|
||
it(`throws invalid config type from "invalid-type.config.js"`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid-type.config.js' }) | ||
).rejects.toThrow(MetadataValidationError); | ||
}); | ||
|
||
it(`throws invalid config type from "invalid-type.function.js"`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid-type.function.js' }) | ||
).rejects.toThrow(MetadataValidationError); | ||
}); | ||
|
||
it(`throws invalid config type from "invalid-type.async.js"`, async () => { | ||
await expect( | ||
loadConfigAsync({ projectDir, metadataPath: 'invalid-type.async.js' }) | ||
).rejects.toThrow(MetadataValidationError); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/eas-cli/src/metadata/__tests__/fixtures/invalid-type.async.js
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,3 @@ | ||
module.exports = async function () { | ||
return await Promise.resolve(null); | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/eas-cli/src/metadata/__tests__/fixtures/invalid-type.config.js
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 @@ | ||
module.exports = 1337; |
5 changes: 5 additions & 0 deletions
5
packages/eas-cli/src/metadata/__tests__/fixtures/invalid-type.config.json
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,5 @@ | ||
[ | ||
{ | ||
"configVersion": -1 | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
packages/eas-cli/src/metadata/__tests__/fixtures/invalid-type.function.js
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,3 @@ | ||
module.exports = function () { | ||
return true; | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/eas-cli/src/metadata/__tests__/fixtures/invalid.async.js
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,3 @@ | ||
module.exports = async function () { | ||
return await Promise.resolve({ configVersion: -1 }); | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/eas-cli/src/metadata/__tests__/fixtures/invalid.config.js
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,3 @@ | ||
module.exports = { | ||
configVersion: -1, | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/eas-cli/src/metadata/__tests__/fixtures/invalid.config.json
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,3 @@ | ||
{ | ||
"configVersion": -1 | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/eas-cli/src/metadata/__tests__/fixtures/invalid.function.js
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,3 @@ | ||
module.exports = function () { | ||
return { configVersion: -1 }; | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/eas-cli/src/metadata/__tests__/fixtures/store.async.js
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,5 @@ | ||
module.exports = async function () { | ||
const config = require('./store.config.json'); | ||
config.apple.copyright = `${new Date().getFullYear()} ACME`; | ||
return await Promise.resolve(config); | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/eas-cli/src/metadata/__tests__/fixtures/store.config.js
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,5 @@ | ||
const config = require('./store.config.json'); | ||
|
||
config.apple.copyright = `${new Date().getFullYear()} ACME`; | ||
|
||
module.exports = config; |
22 changes: 22 additions & 0 deletions
22
packages/eas-cli/src/metadata/__tests__/fixtures/store.config.json
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,22 @@ | ||
{ | ||
"configVersion": 0, | ||
"apple": { | ||
"copyright": "ACME", | ||
"info": { | ||
"en-US": { | ||
"title": "App title", | ||
"subtitle": "Subtitle for your app", | ||
"description": "A longer description of what your app does", | ||
"keywords": [ | ||
"keyword" | ||
], | ||
"releaseNotes": "Bug fixes and improved stability", | ||
"promoText": "Short tagline for your app", | ||
"marketingUrl": "https://example.com/en/marketing", | ||
"supportUrl": "https://example.com/en/support", | ||
"privacyPolicyUrl": "https://example.com/en/privacy", | ||
"privacyChoicesUrl": "https://example.com/en/choices" | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/eas-cli/src/metadata/__tests__/fixtures/store.function.js
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,5 @@ | ||
module.exports = function () { | ||
const config = require('./store.config.json'); | ||
config.apple.copyright = `${new Date().getFullYear()} ACME`; | ||
return config; | ||
}; |
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.