Skip to content

Commit

Permalink
Fix error text grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
mesaugat committed Mar 27, 2021
1 parent 18106cc commit 2d6b973
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
15 changes: 7 additions & 8 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import ConnectionsFileSchema from './domain/ConnectionsFileSchema';
import { prepareInjectionConfigVars } from './service/configInjection';
import { DEFAULT_CONFIG, CONFIG_FILENAME, CONNECTIONS_FILENAME, REQUIRED_ENV_KEYS } from './constants';

const CONFIG_FILE_CONVENTION = /^sync-db-[\w]+\.yml$/;

const CONFIG_FILE_CONVENTION = /^sync-db-\w+\.yml$/;
interface ConnectionResolver {
resolve: (config: Configuration) => Promise<ConnectionConfig[]>;
}
Expand Down Expand Up @@ -45,15 +44,15 @@ export function getSqlBasePath(config: Configuration): string {
*/
export async function loadConfig(configFilename: string = CONFIG_FILENAME): Promise<Configuration> {
log('Resolving config file.');
const isConfigFilePathAbsolute = path.isAbsolute(configFilename);
const filename = isConfigFilePathAbsolute ? path.parse(configFilename).base : configFilename;
const filenameMatched = filename.match(CONFIG_FILE_CONVENTION) || filename === CONFIG_FILENAME;
const isAbsolutePath = path.isAbsolute(configFilename);
const filename = isAbsolutePath ? path.parse(configFilename).base : configFilename;
const match = filename.match(CONFIG_FILE_CONVENTION) || filename === CONFIG_FILENAME;

if (!filenameMatched) {
throw new Error(`The config filename doesn't meet the pattern (sync-db.yml or sync-db-*.yml)`);
if (!match) {
throw new Error(`The config filename doesn't match the pattern sync-db.yml or sync-db-*.yml`);
}

const filepath = isConfigFilePathAbsolute ? configFilename : path.join(process.cwd(), configFilename);
const filepath = isAbsolutePath ? configFilename : path.join(process.cwd(), configFilename);
const loadedConfig = (await yaml.load(filepath)) as Configuration;

log('Resolved config file.');
Expand Down
14 changes: 7 additions & 7 deletions test/unit/util/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('CONFIG:', () => {

await expect(loadConfig('sync-db-test.yml')).not.to.be.rejectedWith(
Error,
`The config filename doesn't meet the pattern (sync-db.yml or sync-db-*.yml)`
`The config filename doesn't match the pattern sync-db.yml or sync-db-*.yml`
);

const config = await loadConfig('sync-db-test.yml');
Expand All @@ -172,27 +172,27 @@ describe('CONFIG:', () => {
it(`should throw an error if the config file doesn't match the naming convention.`, async () => {
await expect(loadConfig('sync-db.txt')).to.be.rejectedWith(
Error,
`The config filename doesn't meet the pattern (sync-db.yml or sync-db-*.yml)`
`The config filename doesn't match the pattern sync-db.yml or sync-db-*.yml`
);
await expect(loadConfig('sync-db-test.js')).to.be.rejectedWith(
Error,
`The config filename doesn't meet the pattern (sync-db.yml or sync-db-*.yml)`
`The config filename doesn't match the pattern sync-db.yml or sync-db-*.yml`
);
await expect(loadConfig('sync.yml')).to.be.rejectedWith(
Error,
`The config filename doesn't meet the pattern (sync-db.yml or sync-db-*.yml)`
`The config filename doesn't match the pattern sync-db.yml or sync-db-*.yml`
);
await expect(loadConfig('sync-db.yml.txt')).to.be.rejectedWith(
Error,
`The config filename doesn't meet the pattern (sync-db.yml or sync-db-*.yml)`
`The config filename doesn't match the pattern sync-db.yml or sync-db-*.yml`
);
await expect(loadConfig('sync-db-.yml')).to.be.rejectedWith(
Error,
`The config filename doesn't meet the pattern (sync-db.yml or sync-db-*.yml)`
`The config filename doesn't match the pattern sync-db.yml or sync-db-*.yml`
);
await expect(loadConfig('sync-dbasdfghjkl.yml')).to.be.rejectedWith(
Error,
`The config filename doesn't meet the pattern (sync-db.yml or sync-db-*.yml)`
`The config filename doesn't match the pattern sync-db.yml or sync-db-*.yml`
);
});

Expand Down

0 comments on commit 2d6b973

Please sign in to comment.