Skip to content

Commit 2ccf148

Browse files
committed
chore: add unit tests
1 parent e17abb3 commit 2ccf148

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

internal/functions/deploy/testdata/geometries/Geometries.js

Whitespace-only changes.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import {
2+
Component
3+
} from '@angular2/core';
4+
import defaultMember from "module-name";
5+
import * as name from "module-name ";
6+
import { member } from " module-name";
7+
import { member as alias } from "module-name";
8+
import { member1 , member2 } from "module-name";
9+
import { member1 , member2 as alias2 , member3 as alias3 } from "module-name";
10+
import {
11+
Component
12+
} from '@angular2/core';
13+
import defaultMember from "$module-name";
14+
import defaultMember, { member, member } from "module-name";
15+
import defaultMember, * as name from "module-name";
16+
17+
import * as name from "module-name "
18+
import { member } from " module-name"
19+
import { member as alias } from "module-name"
20+
import { member1 , member2 } from "module-name"
21+
import { member1 , member2 as alias2 , member3 as alias3 } from "module-name"
22+
import {
23+
Component
24+
} from '@angular2/core'
25+
import defaultMember from "$module-name"
26+
import defaultMember, { member, member } from "module-name"
27+
import defaultMember, * as name from "module-name"
28+
29+
import "module-name";
30+
import React from "react"
31+
import { Field } from "redux-form"
32+
import "module-name";
33+
34+
import {
35+
PlaneBufferGeometry,
36+
OctahedronGeometry,
37+
TorusBufferGeometry
38+
} from '../geometries/Geometries.js';
39+
40+
import {
41+
PlaneBufferGeometry,
42+
OctahedronGeometry,
43+
TorusBufferGeometry
44+
} from '../geometries/Geometries.js'
45+
46+
import("module-name/whatever.ts");
47+
import("module-name/whatever.ts")
48+
49+
import { Field } from "redux-form";
50+
import MultiContentListView from "./views/ListView";
51+
import MultiContentAddView from "./views/AddView";
52+
import MultiContentEditView from "./views/EditView";
53+
54+
import { Field } from "redux-form"
55+
import MultiContentListView from "./views/ListView"
56+
import MultiContentAddView from "./views/AddView"
57+
import MultiContentEditView from "./views/EditView"
58+
59+
60+
<MenuItem value="^$" primaryText="Não exibir importados" />
61+
<MenuItem value="\\w+" primaryText="Exibir importados" />
62+
63+
// *Add all needed dependency to this module
64+
// *app requires those import modules to function
65+
66+
67+
/**
68+
*
69+
*Add all needed dependency to this module
70+
*app requires those import modules to function
71+
*
72+
**/
73+
74+
let modules = [];
75+
76+
77+
import defaultExport from "module-name";
78+
import * as name from "module-name";
79+
import { export1 } from "module-name";
80+
import { export1 as alias1 } from "module-name";
81+
import { default as alias } from "module-name";
82+
import { export1, export2 } from "module-name";
83+
import { export1, export2 as alias2, /* … */ } from "module-name";
84+
import { "string name" as alias } from "module-name";
85+
import defaultExport, { export1, /* … */ } from "module-name";
86+
import defaultExport, * as name from "module-name";
87+
import "module-name";
88+
import { "a-b" as a } from "/modules/my-module.ts";
89+
import myDefault from "/modules/my-module.ts";
90+
import myDefault, * as myModule from "/modules/my-module.ts";

internal/functions/deploy/testdata/nested/index.ts

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import * from '../nested/index.ts';
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package deploy
2+
3+
import (
4+
"embed"
5+
"io"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/mock"
10+
"github.com/supabase/cli/internal/utils"
11+
)
12+
13+
//go:embed testdata
14+
var testImports embed.FS
15+
16+
type MockFS struct {
17+
mock.Mock
18+
}
19+
20+
func (m *MockFS) ReadFile(srcPath string, w io.Writer) error {
21+
_ = m.Called(srcPath)
22+
data, err := testImports.ReadFile(srcPath)
23+
if err != nil {
24+
return err
25+
}
26+
if _, err := w.Write(data); err != nil {
27+
return err
28+
}
29+
return nil
30+
}
31+
32+
func TestImportPaths(t *testing.T) {
33+
t.Run("iterates all import paths", func(t *testing.T) {
34+
// Setup in-memory fs
35+
fsys := MockFS{}
36+
fsys.On("ReadFile", "/modules/my-module.ts").Once()
37+
fsys.On("ReadFile", "testdata/modules/imports.ts").Once()
38+
fsys.On("ReadFile", "testdata/geometries/Geometries.js").Once()
39+
// Run test
40+
im := utils.ImportMap{}
41+
err := walkImportPaths("testdata/modules/imports.ts", im, fsys.ReadFile)
42+
// Check error
43+
assert.NoError(t, err)
44+
fsys.AssertExpectations(t)
45+
})
46+
47+
t.Run("iterates with import map", func(t *testing.T) {
48+
// Setup in-memory fs
49+
fsys := MockFS{}
50+
fsys.On("ReadFile", "/modules/my-module.ts").Once()
51+
fsys.On("ReadFile", "testdata/modules/imports.ts").Once()
52+
fsys.On("ReadFile", "testdata/geometries/Geometries.js").Once()
53+
fsys.On("ReadFile", "testdata/shared/whatever.ts").Once()
54+
fsys.On("ReadFile", "testdata/nested/index.ts").Once()
55+
// Run test
56+
im := utils.ImportMap{Imports: map[string]string{
57+
"module-name/": "../shared/",
58+
}}
59+
err := walkImportPaths("testdata/modules/imports.ts", im, fsys.ReadFile)
60+
// Check error
61+
assert.NoError(t, err)
62+
fsys.AssertExpectations(t)
63+
})
64+
}

0 commit comments

Comments
 (0)