Skip to content

🎥 Make videos programmatically with React

test for some bugs - nothing found!

Jonny Burger8554600179f8
diff --git a/packages/renderer/src/test/actual-concurrency.test.ts b/packages/renderer/src/test/actual-concurrency.test.ts
new file mode 100644
index 0000000000..943ecd567a
--- /dev/null
+++ b/packages/renderer/src/test/actual-concurrency.test.ts
@@ -0,0 +1,27 @@
+import os from 'os';
+import {expect, test} from 'vitest';
+import {getActualConcurrency} from '../get-concurrency';
+
+test('Actual concurrency null should choose a good result', () => {
+ expect(getActualConcurrency(null)).toBe(
+ Math.round(Math.min(8, Math.max(1, os.cpus().length / 2)))
+ );
+});
+
+test('50% should yield half the cores', () => {
+ expect(getActualConcurrency('50%')).toBe(
+ Math.round(Math.min(8, Math.max(1, os.cpus().length / 2)))
+ );
+});
+
+test('75% should be 3/4 of the cores', () => {
+ expect(getActualConcurrency('75%')).toBe(Math.round(os.cpus().length * 0.75));
+});
+
+test('Slightly over 100% is ok as long as it is rounded', () => {
+ expect(getActualConcurrency('100.2%')).toBe(os.cpus().length);
+});
+
+test('Should also accept integers', () => {
+ expect(getActualConcurrency(1)).toBe(1);
+});
diff --git a/packages/renderer/src/test/validate-concurrency.test.ts b/packages/renderer/src/test/validate-concurrency.test.ts
index e0aaa709e7..fbb7b4dd6b 100644
--- a/packages/renderer/src/test/validate-concurrency.test.ts
+++ b/packages/renderer/src/test/validate-concurrency.test.ts
@@ -18,3 +18,13 @@ test('setConcurrency should throw if concurrency is too high', () => {
/concurrencyPerLambda is set higher than the amount of CPU cores available/
);
});
+
+test('setConcurrency should throw if concurrency is too high', () => {
+ expect(() => validateConcurrency('0', 'concurrency')).toThrow(
+ /concurrency must be a number or percentage, but is "0"/
+ );
+});
+
+test('setConcurrency should throw if concurrency is too high', () => {
+ expect(validateConcurrency('50%', 'concurrency')).toBe(undefined);
+});
diff --git a/packages/renderer/src/validate-concurrency.ts b/packages/renderer/src/validate-concurrency.ts
index 8d68d573ee..f72e349e03 100644
--- a/packages/renderer/src/validate-concurrency.ts
+++ b/packages/renderer/src/validate-concurrency.ts
@@ -27,7 +27,11 @@ export const validateConcurrency = (value: unknown, setting: string) => {
}, value set: ${value}`
);
}
- } else if(!(/^\d+(\.\d+)?%$/.test(value))) {
- throw new Error(setting + ' must be a number or percentage, but is ' + value);
+ } else if (!/^\d+(\.\d+)?%$/.test(value)) {
+ throw new Error(
+ `${setting} must be a number or percentage, but is ${JSON.stringify(
+ value
+ )}`
+ );
}
};