Skip to content

Commit

Permalink
Add URL test
Browse files Browse the repository at this point in the history
  • Loading branch information
drwpow committed Jul 14, 2023
1 parent fad5d8d commit 3812019
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
node-version: 20
- uses: pnpm/action-setup@v2
with:
version: latest
version: 8
- run: pnpm i
- run: pnpm run lint
test:
Expand All @@ -28,7 +28,7 @@ jobs:
node-version: 20
- uses: pnpm/action-setup@v2
with:
version: latest
version: 8
- run: pnpm i
- run: pnpm run build
- run: pnpm test
9 changes: 4 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
with:
node-version: 20
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: latest
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
version: 8
- run: pnpm i
- run: pnpm run build
- uses: changesets/action@v1
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ async function main() {
try {
// if running `co check [tokens]`, don’t load config from file
if (cmd === 'check' && args[0]) {
console.log(args[0]);
config = await initConfig({tokens: args[0]}, cwd);
} else {
config = await loadConfig(resolveConfig(configPath));
Expand Down Expand Up @@ -137,8 +136,9 @@ async function main() {
break;
}
case 'check': {
console.log(`${UNDERLINE}${fileURLToPath(config.tokens[0])}${RESET}`);
const rawSchema = await loadTokens(config.tokens);
const filepath = config.tokens[0];
console.log(`${UNDERLINE}${filepath.protocol === 'file:' ? fileURLToPath(filepath) : filepath}${RESET}`);
const {errors, warnings} = parse(rawSchema, config); // will throw if errors
if (errors || warnings) {
printErrors(errors);
Expand Down Expand Up @@ -210,9 +210,10 @@ async function loadTokens(tokenPaths) {
for (const filepath of tokenPaths) {
const pathname = filepath.pathname.toLowerCase();
const isYAMLExt = pathname.endsWith('.yaml') || pathname.endsWith('.yml');
if (filepath.protocol === 'url:') {
if (filepath.protocol === 'http:' || filepath.protocol === 'https:') {
try {
const raw = await globalThis.fetch(filepath, {method: 'GET', headers: {Accepted: '*/*', 'User-Agent': 'cobalt'}}).then((res) => res.text());
const res = await globalThis.fetch(filepath, {method: 'GET', headers: {Accept: '*/*', 'User-Agent': 'Mozilla/5.0 Gecko/20100101 Firefox/116.0'}});
const raw = await res.text();
if (isYAMLExt || res.headers.get('content-type').includes('yaml')) {
rawTokens.push(yaml.load(raw));
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/test/check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ describe('co check', () => {
expect(result.exitCode).toBe(0);
});

test('URL', async () => {
const result = await execa('node', ['./bin/cli.js', 'check', 'https://raw.githubusercontent.com/drwpow/cobalt-ui/main/packages/cli/test/fixtures/check-default/tokens.json']);
expect(result.exitCode).toBe(0);
});

test('invalid tokens', async () => {
const cwd = new URL('./fixtures/check-invalid/', import.meta.url);
await expect(async () => await execa('node', [cmd, 'check'], {cwd, throwOnStderr: false})).rejects.toThrow();
Expand Down

0 comments on commit 3812019

Please sign in to comment.