-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
70 lines (61 loc) · 2.24 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-env mocha */
'use strict';
const assert = require('assert').strict;
const detective = require('../index.js');
describe('detective-vue2', () => {
it('throws if the source content is not given', () => {
assert.throws(() => {
detective();
}, /^Error: content not given$/);
});
it('throws if the source content is not a string', () => {
assert.throws(() => {
detective(() => {});
}, /^Error: content is not a string$/);
});
it('retrieves the dependencies of script block lang ts', () => {
const deps = detective('<template></template> <script lang="ts">import {foo, bar} from "mylib"; </script>');
assert.equal(deps.length, 1);
assert.equal(deps[0], 'mylib');
});
it('retrieves the dependencies of scss and script block lang ts', () => {
const deps = detective('<template></template> <script lang="ts">import {foo, bar} from "mylib"; </script> <style lang="scss">@import \'vars.scss\' </style>');
assert.equal(deps.length, 2);
assert.equal(deps[0], 'mylib');
assert.equal(deps[1], 'vars.scss');
});
it('retrieves the dependencies of scss and script block lang js', () => {
const deps = detective('<template></template> <script>import {foo, bar} from "mylib"; </script> <style lang="sass">@import \'vars.scss\' </style>');
assert.equal(deps.length, 2);
assert.equal(deps[0], 'mylib');
assert.equal(deps[1], 'vars.scss');
});
it('retrieves the dependencies of script block lang ts using setup syntax', () => {
const deps = detective(`<script lang="ts" setup>
import { foo, bar } from "mylib";
import OtherComponent from "./OtherComponent.vue";
</script>
<template>
<OtherComponent />
</template>
`);
assert.equal(deps.length, 2);
assert.equal(deps[0], 'mylib');
assert.equal(deps[1], './OtherComponent.vue');
});
it('retrieves the dependencies of script block lang ts using both setup and normal syntax', () => {
const deps = detective(`<script lang="ts">
import { foo, bar } from "mylib";
</script>
<script setup lang="ts">
import OtherComponent from "./OtherComponent.vue";
</script>
<template>
<OtherComponent />
</template>
`);
assert.equal(deps.length, 2);
assert.equal(deps[0], 'mylib');
assert.equal(deps[1], './OtherComponent.vue');
});
});