Skip to content

Commit

Permalink
fix(rules): add Cloudflare provider
Browse files Browse the repository at this point in the history
  • Loading branch information
bodinsamuel committed Jul 4, 2023
1 parent 3c862f6 commit 5567105
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 60 deletions.
2 changes: 2 additions & 0 deletions src/common/techs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const list: TechItem[] = [
{ key: 'cassandra', name: 'Cassandra', type: 'db' },
{ key: 'circleci', name: 'CircleCi', type: 'ci' },
{ key: 'cirrusci', name: 'CirrusCi', type: 'ci' },
{ key: 'couchbase', name: 'Couchbase', type: 'db' },
{ key: 'cloudflare', name: 'Cloudflare', type: 'hosting' },
{ key: 'codesandboxci', name: 'CodesandboxCI', type: 'ci' },
{ key: 'couchbase', name: 'Couchbase', type: 'db' },
{ key: 'cplusplus', name: 'C++', type: 'language' },
Expand Down
23 changes: 23 additions & 0 deletions src/rules/__snapshots__/ci.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`ci > should match everything 1`] = `
[
"appveyor",
"azure.ci",
"browserstack",
"circleci",
"cirrusci",
"codesandboxci",
"cypressci",
"dependabot",
"github.actions",
"gitlabci",
"javascript",
"jenkins",
"relativeci",
"renovate",
"styleci",
"teamcity",
"travisci",
]
`;
14 changes: 14 additions & 0 deletions src/rules/__snapshots__/hosting.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`hosting > should match everything with files 1`] = `
[
"expodev",
"flyio",
"github.pages",
"heroku",
"netlify",
"platformsh",
"render",
"vercel",
]
`;
47 changes: 14 additions & 33 deletions src/rules/ci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import { FakeProvider } from '../provider/fake.js';
import { rawList } from '../rules.js';
import './index.js';

const paths: string[] = [];
for (const item of rawList) {
if (
item.type !== 'file' ||
listIndexed[item.ref.tech].type !== 'ci' ||
!item.ref.files
) {
continue;
}

paths.push('example' in item.ref ? item.ref.example : item.ref.files[0]);
}

describe('ci', () => {
it('should match everything', async () => {
const paths: string[] = [];
for (const item of rawList) {
if (
item.type !== 'file' ||
listIndexed[item.ref.tech].type !== 'ci' ||
!item.ref.files
) {
continue;
}

paths.push('example' in item.ref ? item.ref.example : item.ref.files[0]);
}

const res = await analyser({
provider: new FakeProvider({
paths: {
Expand All @@ -30,26 +30,7 @@ describe('ci', () => {
files: {},
}),
});
const match: AllowedKeys[] = [
'appveyor',
'azure.ci',
'browserstack',
'circleci',
'cirrusci',
'codesandboxci',
'cypressci',
'dependabot',
'github.actions',
'gitlabci',
'javascript',
'jenkins',
'relativeci',
'renovate',
'styleci',
'teamcity',
'travisci',
];
expect(res.toJson('').techs).toStrictEqual(match);
expect(res.toJson('').techs).toMatchSnapshot();
});

it('enforce that we match .github', async () => {
Expand Down
39 changes: 14 additions & 25 deletions src/rules/hosting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@ import { describe, expect, it } from 'vitest';

import { analyser } from '../analyser/index.js';
import { listIndexed } from '../common/techs.js';
import type { AllowedKeys } from '../index.js';
import { FakeProvider } from '../provider/fake.js';
import { rawList } from '../rules.js';
import './index.js';

const paths: string[] = [];
for (const item of rawList) {
if (
item.type !== 'file' ||
listIndexed[item.ref.tech].type !== 'hosting' ||
!item.ref.files
) {
continue;
}

paths.push('example' in item.ref ? item.ref.example : item.ref.files[0]);
}

describe('hosting', () => {
it('should match everything with files', async () => {
const paths: string[] = [];
for (const item of rawList) {
if (
item.type !== 'file' ||
listIndexed[item.ref.tech].type !== 'hosting' ||
!item.ref.files
) {
continue;
}

paths.push('example' in item.ref ? item.ref.example : item.ref.files[0]);
}

const res = await analyser({
provider: new FakeProvider({
paths: {
Expand All @@ -30,16 +29,6 @@ describe('hosting', () => {
files: {},
}),
});
const match: AllowedKeys[] = [
'expodev',
'flyio',
'github.pages',
'heroku',
'netlify',
'platformsh',
'render',
'vercel',
];
expect(res.toJson('').techs).toStrictEqual(match);
expect(res.toJson('').techs).toMatchSnapshot();
});
});
8 changes: 8 additions & 0 deletions src/rules/hosting/cloudflare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { register } from '../../rules.js';

register({
tech: 'cloudflare',
dependencies: [
{ type: 'terraform', name: 'registry.terraform.io/cloudflare/cloudflare' },
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

exports[`docker > should match everything 1`] = `
[
"aws",
"aws.dynamodb",
"caddy",
"cassandra",
"couchbase",
"cypressci",
"docker",
"dynamodb",
"elasticsearch",
"httpd",
"influxdb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ exports[`npm > should match everything 1`] = `
"angular",
"auth0",
"aws",
"aws.dynamodb",
"bootstrap",
"browserstack",
"couchbase",
"cypressci",
"datadog",
"dynamodb",
"elasticsearch",
"esbuild",
"eslint",
Expand Down
1 change: 1 addition & 0 deletions src/types/techs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type AllowedKeys =
| 'cassandra'
| 'circleci'
| 'cirrusci'
| 'cloudflare'
| 'codesandboxci'
| 'couchbase'
| 'cplusplus'
Expand Down

0 comments on commit 5567105

Please sign in to comment.