Skip to content

Commit

Permalink
feat: fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanphamcybozu committed May 23, 2024
1 parent f808f2b commit 1d1b116
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions packages/plugin-manifest-validator/src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import validator from "../index";

// 20MB
const MAX_FILE_SIZE = 20 * 1024 * 1024;
const VALID_SCHEMA_PATTERN = '^(https:\\/\\/[^\\s/$.?#].[^\\s]*|\\/[^\\s]*|(\\.\\/|\\.\\.\\/|)(?!http:\\/\\/)[^\\s]*)$';
const VALID_SCHEMA_PATTERN =
"^(https:\\/\\/[^\\s/$.?#].[^\\s]*|\\/[^\\s]*|(\\.\\/|\\.\\.\\/|)(?!http:\\/\\/)[^\\s]*)$";

describe("validator", () => {
it("is a function", () => {
Expand Down Expand Up @@ -40,14 +41,18 @@ describe("validator", () => {
it("https url", () => {
assert.deepStrictEqual(
validator(json({ $schema: "https://secure-url.com/schema.json" })),
{ valid: true, errors: null },
{ valid: true, errors: null }
);

});
it("relative path", () => {
assert.deepStrictEqual(
validator(json({ $schema: "./node_modules/@kintone/plugin-manifest-validator/manifest-schema.json" })),
{ valid: true, errors: null },
validator(
json({
$schema:
"./node_modules/@kintone/plugin-manifest-validator/manifest-schema.json",
})
),
{ valid: true, errors: null }
);
});
});
Expand All @@ -69,11 +74,11 @@ describe("validator", () => {
schemaPath: "#/properties/%24schema/pattern",
},
],
},
}
);
});
});
})
});

describe("version", () => {
it.each(
Expand All @@ -86,7 +91,7 @@ describe("validator", () => {
"2.0.3",
0,
10
],
]
)("valid version: %s", (version) => {
expect(validator(json({ version }))).toStrictEqual({
valid: true,
Expand Down Expand Up @@ -199,24 +204,24 @@ describe("validator", () => {
json({
manifest_version: "a",
version: -1,
}),
})
);
const invalidManifestVersion = validator(
json({
manifest_version: "a",
}),
})
);
const invalidVersion = validator(
json({
version: -1,
}),
})
);
expect(actual.valid).toBe(false);
expect(actual.errors).toStrictEqual(
expect.arrayContaining([
...(invalidManifestVersion.errors ?? []),
...(invalidVersion.errors ?? []),
]),
])
);
});

Expand All @@ -236,7 +241,7 @@ describe("validator", () => {
}),
{
relativePath: (str) => !/^https?:/.test(str),
},
}
);
assert(actual.valid === false);
assert(actual.errors?.length === 3);
Expand Down Expand Up @@ -290,7 +295,7 @@ describe("validator", () => {
maxFileSize: (maxFileSizeInBytes, path) => {
return path.indexOf("foo.js") === -1;
},
},
}
);
assert(actual.valid === false);
assert(actual.errors?.length === 3);
Expand All @@ -316,7 +321,7 @@ describe("validator", () => {
maxFileSize: (maxFileSizeInBytes, path) => {
return path.indexOf("foo.css") === -1;
},
},
}
);
assert(actual.valid === false);
assert(actual.errors?.length === 3);
Expand Down Expand Up @@ -362,7 +367,7 @@ describe("validator", () => {
js: ["https://example.com/foo.js"],
css: ["https://example.com/foo.css"],
},
}),
})
);
assert(actual.valid === true);
assert(actual.errors === null);
Expand Down Expand Up @@ -424,7 +429,7 @@ describe("validator", () => {
message: `file should exist ("${filePath}")`,
schemaPath,
});
},
}
);

it.each`
Expand Down Expand Up @@ -480,21 +485,21 @@ describe("validator", () => {
message: customMessage,
schemaPath,
});
},
}
);
});

describe("maxItems", () => {
it("exceed the max item counts", () => {
const urls = [...new Array(100)].map(
(_, i) => `https://example.com/${i}.js`,
(_, i) => `https://example.com/${i}.js`
);
const actual = validator(
json({
desktop: {
js: urls,
},
}),
})
);
assert.strictEqual(actual.valid, false);
assert.strictEqual(actual.errors?.length, 1);
Expand Down Expand Up @@ -540,7 +545,7 @@ describe("validator", () => {
valid: true,
errors: null,
});
},
}
);
});
});
Expand All @@ -562,6 +567,6 @@ const json = (source: Record<string, any>): { [s: string]: any } => {
},
icon: "image/icon.png",
},
source,
source
);
};

0 comments on commit 1d1b116

Please sign in to comment.