@ryanatkn/gro 0.129.8 → 0.129.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,86 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
- import {Timings} from '@ryanatkn/belt/timings.js';
4
-
5
- import {run_task} from './run_task.js';
6
- import {load_config} from './config.js';
7
-
8
- test('passes args and returns output', async () => {
9
- const args = {a: 1, _: []};
10
- const result = await run_task(
11
- {
12
- name: 'testTask',
13
- id: 'foo/testTask',
14
- mod: {
15
- task: {
16
- run: ({args}) => Promise.resolve(args),
17
- },
18
- },
19
- },
20
- args,
21
- () => Promise.resolve(),
22
- await load_config(),
23
- new Timings(),
24
- );
25
- assert.ok(result.ok);
26
- assert.is(result.output, args);
27
- });
28
-
29
- test('invokes a sub task', async () => {
30
- const args = {a: 1, _: []};
31
- let invoked_task_name;
32
- let invoked_args;
33
- const result = await run_task(
34
- {
35
- name: 'testTask',
36
- id: 'foo/testTask',
37
- mod: {
38
- task: {
39
- run: async ({args, invoke_task}) => {
40
- await invoke_task('bar/testTask', args);
41
- return args;
42
- },
43
- },
44
- },
45
- },
46
- args,
47
- (invoking_task_name, invoking_args) => {
48
- invoked_task_name = invoking_task_name;
49
- invoked_args = invoking_args;
50
- return Promise.resolve();
51
- },
52
- await load_config(),
53
- new Timings(),
54
- );
55
- assert.ok(result.ok);
56
- assert.is(invoked_task_name, 'bar/testTask');
57
- assert.is(invoked_args, args);
58
- assert.is(result.output, args);
59
- });
60
-
61
- test('failing task', async () => {
62
- let err;
63
- const result = await run_task(
64
- {
65
- name: 'testTask',
66
- id: 'foo/testTask',
67
- mod: {
68
- task: {
69
- run: () => {
70
- err = Error();
71
- throw err;
72
- },
73
- },
74
- },
75
- },
76
- {_: []},
77
- async () => {}, // eslint-disable-line @typescript-eslint/no-empty-function
78
- await load_config(),
79
- new Timings(),
80
- );
81
- assert.ok(!result.ok);
82
- assert.ok(result.reason);
83
- assert.is(result.error, err);
84
- });
85
-
86
- test.run();
@@ -1,56 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
- import {resolve} from 'node:path';
4
-
5
- import {search_fs} from './search_fs.js';
6
-
7
- test('search_fs basic behavior', () => {
8
- const ignored_path = 'test1.foo.ts';
9
- let has_ignored_path = false;
10
- const result = search_fs('./src/fixtures', {
11
- filter: (path) => {
12
- if (!has_ignored_path) has_ignored_path = path.endsWith(ignored_path);
13
- return !path.endsWith(ignored_path);
14
- },
15
- sort: (a, b) => a.path.localeCompare(b.path) * -1,
16
- });
17
- assert.ok(has_ignored_path); // makes sure the test isn't wrong
18
- const expected_files = [
19
- 'test2.foo.ts',
20
- 'test_ts.ts',
21
- 'test_task_module.task_fixture.ts',
22
- 'test_js.js',
23
- 'test_invalid_task_module.ts',
24
- 'test_file.other.ext',
25
- 'test_failing_task_module.ts',
26
- 'some_test_side_effect.ts',
27
- 'some_test_json.json',
28
- 'some_test_exports3.ts',
29
- 'some_test_exports2.ts',
30
- 'some_test_exports.ts',
31
- 'modules/some_test_ts.ts',
32
- 'modules/Some_Test_Svelte.svelte',
33
- 'modules/some_test_svelte_ts.svelte.ts',
34
- 'modules/some_test_svelte_js.svelte.js',
35
- 'modules/some_test_server.ts',
36
- 'modules/some_test_json.json',
37
- 'modules/some_test_js.js',
38
- 'modules/some_test_css.css',
39
- 'changelog_example.md',
40
- 'changelog_cache.json',
41
- 'baz2/test2.baz.ts',
42
- 'baz1/test1.baz.ts',
43
- 'bar2/test2.bar.ts',
44
- 'bar1/test1.bar.ts',
45
- ];
46
- assert.equal(
47
- result.map((f) => f.path),
48
- expected_files,
49
- );
50
- assert.equal(
51
- result.map((f) => f.id),
52
- expected_files.map((f) => resolve(`src/fixtures/${f}`)),
53
- );
54
- });
55
-
56
- test.run();
@@ -1,49 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
-
4
- import {to_src_modules} from './src_json.js';
5
- import {to_package_exports} from './package_json.js';
6
- import {paths} from './paths.js';
7
-
8
- test('to_package_modules', () => {
9
- assert.equal(
10
- to_src_modules(
11
- to_package_exports([
12
- 'fixtures/modules/some_test_css.css',
13
- 'fixtures/modules/Some_Test_Svelte.svelte',
14
- 'fixtures/modules/some_test_ts.ts',
15
- 'fixtures/modules/some_test_json.json',
16
- ]),
17
- undefined,
18
- paths.source,
19
- ),
20
- {
21
- './package.json': {path: 'package.json', declarations: []},
22
- './fixtures/modules/some_test_css.css': {
23
- path: 'fixtures/modules/some_test_css.css',
24
- declarations: [],
25
- },
26
- './fixtures/modules/some_test_json.json': {
27
- path: 'fixtures/modules/some_test_json.json',
28
- declarations: [],
29
- },
30
- './fixtures/modules/Some_Test_Svelte.svelte': {
31
- path: 'fixtures/modules/Some_Test_Svelte.svelte',
32
- declarations: [],
33
- },
34
- './fixtures/modules/some_test_ts.js': {
35
- path: 'fixtures/modules/some_test_ts.ts',
36
- declarations: [
37
- {name: 'a', kind: 'variable'},
38
- {name: 'some_test_ts', kind: 'variable'},
39
- {name: 'some_test_fn', kind: 'function'},
40
- {name: 'Some_Test_Type', kind: 'type'},
41
- {name: 'Some_Test_Interface', kind: 'type'},
42
- {name: 'Some_Test_Class', kind: 'class'},
43
- ],
44
- },
45
- },
46
- );
47
- });
48
-
49
- test.run();
@@ -1,84 +0,0 @@
1
- import {test} from 'uvu';
2
- import * as assert from 'uvu/assert';
3
- import {resolve} from 'node:path';
4
-
5
- import {is_task_path, to_task_name, validate_task_module, find_tasks, load_tasks} from './task.js';
6
- import * as actual_test_task_module from './test.task.js';
7
- import {create_empty_config} from './config.js';
8
-
9
- test('is_task_path basic behavior', () => {
10
- assert.ok(is_task_path('foo.task.ts'));
11
- assert.ok(is_task_path('foo.task.js'));
12
- assert.ok(!is_task_path('foo.ts'));
13
- assert.ok(is_task_path('bar/baz/foo.task.ts'));
14
- assert.ok(!is_task_path('bar/baz/foo.ts'));
15
- });
16
-
17
- test('to_task_name basic behavior', () => {
18
- assert.is(to_task_name('foo.task.ts', process.cwd(), '', ''), 'foo');
19
- assert.is(to_task_name('bar/baz/foo.task.ts', process.cwd(), '', ''), 'bar/baz/foo');
20
- assert.is(to_task_name('a/b/c/foo.task.ts', 'a/b/c', '', ''), 'foo');
21
- assert.is(to_task_name('a/b/c/foo.task.ts', 'a', '', ''), 'b/c/foo');
22
- assert.is(to_task_name('a/b/c/foo.task.ts', 'a/b', '', ''), 'c/foo');
23
- assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b/d'), '../c/foo');
24
- assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b'), 'c/foo');
25
- assert.is(to_task_name('/a/b/c/foo.task.ts', '/a/b', '/a/b', '/a/b/c'), 'foo');
26
- assert.is(to_task_name('/a/b/d/foo.task.js', '/a/b/d', '/a/b/d/foo', '/a/c'), '../b/d/foo');
27
- assert.is(
28
- to_task_name(
29
- '/a/node_modules/b/c/foo.task.js',
30
- '/a/node_modules/b/c',
31
- '/a/node_modules/b/c/foo',
32
- '/a',
33
- ),
34
- 'foo',
35
- );
36
- assert.is(
37
- to_task_name(
38
- '/a/node_modules/b/c/foo.task.js',
39
- '/a/node_modules/b/c/', // compared to the above, adds a trailing slash here
40
- '/a/node_modules/b/c/foo',
41
- '/a',
42
- ),
43
- 'foo',
44
- );
45
- assert.is(
46
- to_task_name(
47
- '/a/node_modules/b/c/foo.task.js',
48
- '/a/node_modules/b/c',
49
- '/a/node_modules/b/c/foo',
50
- '/a/', // compared to the above, adds a trailing slash here
51
- ),
52
- 'foo',
53
- );
54
- assert.is(
55
- to_task_name(resolve('a/b'), resolve('b'), '', ''),
56
- resolve('a/b'),
57
- 'falls back to the id when unresolved',
58
- );
59
- });
60
-
61
- // TODO if we import directly, svelte-package generates types in `src/fixtures`
62
- const test_task_module = await import('../fixtures/' + 'test_task_module.task_fixture'); // eslint-disable-line no-useless-concat
63
- const test_invalid_task_module = await import('../fixtures/' + 'test_invalid_task_module.js'); // eslint-disable-line no-useless-concat
64
-
65
- test('validate_task_module basic behavior', () => {
66
- assert.ok(validate_task_module(test_task_module));
67
- assert.ok(!validate_task_module(test_invalid_task_module));
68
- assert.ok(!validate_task_module({task: {run: {}}}));
69
- });
70
-
71
- test('load_tasks basic behavior', async () => {
72
- const found = find_tasks(
73
- [resolve('src/lib/test'), resolve('src/lib/test.task.ts')],
74
- [resolve('src/lib')],
75
- create_empty_config(),
76
- );
77
- assert.ok(found.ok);
78
- const result = await load_tasks(found.value);
79
- assert.ok(result.ok);
80
- assert.is(result.value.modules.length, 1);
81
- assert.is(result.value.modules[0].mod, actual_test_task_module);
82
- });
83
-
84
- test.run();
@@ -1,52 +0,0 @@
1
- import {wait} from '@ryanatkn/belt/async.js';
2
- import {test} from 'uvu';
3
- import * as assert from 'uvu/assert';
4
-
5
- import {throttle} from './throttle.js';
6
-
7
- test('throttles calls to a function', async () => {
8
- const results: string[] = [];
9
- const fn = throttle(async (name: string) => {
10
- results.push(name + '_run');
11
- await wait();
12
- results.push(name + '_done');
13
- });
14
- const promise_a = fn('a');
15
- const promise_b = fn('b'); // discarded
16
- const promise_c = fn('c'); // discarded
17
- const promise_d = fn('d');
18
- assert.ok(promise_a !== promise_b);
19
- assert.is(promise_b, promise_c);
20
- assert.is(promise_b, promise_d);
21
- assert.equal(results, ['a_run']);
22
- await promise_a;
23
- assert.equal(results, ['a_run', 'a_done']);
24
- await promise_b;
25
- assert.equal(results, ['a_run', 'a_done', 'd_run', 'd_done']);
26
- const promise_e = fn('e'); // discarded
27
- const promise_f = fn('f');
28
- assert.ok(promise_d !== promise_e);
29
- assert.is(promise_e, promise_f);
30
- assert.equal(results, ['a_run', 'a_done', 'd_run', 'd_done']); // delayed
31
- await wait();
32
- assert.equal(results, ['a_run', 'a_done', 'd_run', 'd_done', 'f_run']);
33
- await promise_e;
34
- assert.equal(results, ['a_run', 'a_done', 'd_run', 'd_done', 'f_run', 'f_done']);
35
- const promise_g = fn('g');
36
- assert.equal(results, ['a_run', 'a_done', 'd_run', 'd_done', 'f_run', 'f_done']); // delayed
37
- await wait();
38
- assert.equal(results, ['a_run', 'a_done', 'd_run', 'd_done', 'f_run', 'f_done', 'g_run']);
39
- await promise_g;
40
- assert.equal(results, [
41
- 'a_run',
42
- 'a_done',
43
- 'd_run',
44
- 'd_done',
45
- 'f_run',
46
- 'f_done',
47
- 'g_run',
48
- 'g_done',
49
- ]);
50
- });
51
-
52
- test.run();