1
+ var exec = require ( 'child_process' ) . exec ;
2
+ var fs = require ( 'fs' ) ;
3
+ var glob = require ( "glob" ) ;
4
+ var testUtils = require ( "./tests.utils" ) ;
5
+ var constants = require ( "./tests.constants" ) ;
6
+
7
+ var _srcReadmeContent = "" ;
8
+
9
+ describe ( 'postclone' , function ( ) {
10
+
11
+ // keep before 'should not init new git repo'
12
+ // in order to avoid getting new files in the git repo
13
+ it ( 'should init new git repo' , function ( done ) {
14
+ testUtils . copySeedDir ( constants . SEED_LOCATION , constants . SEED_COPY_LOCATION , function ( err ) {
15
+ if ( err ) {
16
+ done . fail ( err ) ;
17
+ }
18
+
19
+ testUtils . callPostclone ( constants . SEED_COPY_LOCATION , constants . TEST_GITHUB_USERNAME , constants . TEST_PLUGIN_NAME , "y" , function ( error ) {
20
+ if ( error ) {
21
+ done . fail ( error ) ;
22
+ } else {
23
+ exec ( "cd " + constants . SEED_COPY_LOCATION + "/src && git config --get remote.origin.url" , function ( error , stdout , stderr ) {
24
+ expect ( stdout ) . toEqual ( "" ) ;
25
+ done ( ) ;
26
+ } ) ;
27
+ }
28
+ } ) ;
29
+ } ) ;
30
+ } ) ;
31
+
32
+ it ( 'should not init new git repo' , function ( done ) {
33
+ testUtils . copySeedDir ( constants . SEED_LOCATION , constants . SEED_COPY_LOCATION , function ( err ) {
34
+ if ( err ) {
35
+ done . fail ( err ) ;
36
+ }
37
+
38
+ _srcReadmeContent = fs . readFileSync ( constants . SEED_LOCATION + "/src/README.md" ) ;
39
+ testUtils . callPostclone ( constants . SEED_COPY_LOCATION , constants . TEST_GITHUB_USERNAME , constants . TEST_PLUGIN_NAME , "n" , function ( error , stdout ) {
40
+ if ( error ) {
41
+ done . fail ( error ) ;
42
+ } else {
43
+ exec ( "cd " + constants . SEED_COPY_LOCATION + " && git config --get remote.origin.url" , function ( execError , stdout , stderr ) {
44
+ expect ( stdout ) . toContain ( "NativeScript/nativescript-plugin-seed.git" ) ;
45
+ done ( ) ;
46
+ } ) ;
47
+ }
48
+ } ) ;
49
+ } ) ;
50
+ } ) ;
51
+
52
+ it ( 'should delete the seed screenshots folder' , function ( ) {
53
+ expect ( fs . existsSync ( constants . SEED_COPY_LOCATION + "/screenshots" ) ) . toBeFalsy ( ) ;
54
+ } ) ;
55
+
56
+ it ( 'should delete the seed CONTRIBUTING.md' , function ( ) {
57
+ expect ( fs . existsSync ( constants . SEED_COPY_LOCATION + "/CONTRIBUTING.md" ) ) . toBeFalsy ( ) ;
58
+ } ) ;
59
+
60
+ it ( 'should delete the seed CODE_OF_CONDUCT.md' , function ( ) {
61
+ expect ( fs . existsSync ( constants . SEED_COPY_LOCATION + "/CODE_OF_CONDUCT.md" ) ) . toBeFalsy ( ) ;
62
+ } ) ;
63
+
64
+ it ( 'should delete the postclone.js' , function ( ) {
65
+ expect ( fs . existsSync ( constants . SEED_COPY_LOCATION + "/src/scripts/postclone.js" ) ) . toBeFalsy ( ) ;
66
+ } ) ;
67
+
68
+ it ( 'should delete the seed tests folder' , function ( ) {
69
+ expect ( fs . existsSync ( constants . SEED_COPY_LOCATION + "/seed-tests" ) ) . toBeFalsy ( ) ;
70
+ } ) ;
71
+
72
+ it ( 'should replace the seed README with the plugin one' , function ( ) {
73
+ expect ( fs . existsSync ( constants . SEED_COPY_LOCATION + "/README.md" ) ) . toBeTruthy ( ) ;
74
+ expect ( fs . existsSync ( constants . SEED_COPY_LOCATION + "/src/README.md" ) ) . toBeFalsy ( ) ;
75
+
76
+ var readmeContent = fs . readFileSync ( constants . SEED_COPY_LOCATION + "/README.md" ) ;
77
+ expect ( _srcReadmeContent ) . toEqual ( readmeContent ) ;
78
+ } ) ;
79
+
80
+ it ( 'should rename each yourplugin file' , function ( done ) {
81
+ glob ( constants . SEED_COPY_LOCATION + "/**/yourplugin*.*" , function ( er , files ) {
82
+ expect ( files . length ) . toEqual ( 0 ) ;
83
+ done ( ) ;
84
+ } ) ;
85
+ } ) ;
86
+
87
+ it ( 'should rename each yourplugin file with the new plugin name' , function ( done ) {
88
+ glob ( constants . SEED_COPY_LOCATION + "/**/" + constants . TEST_PLUGIN_NAME + "*.*" , function ( er , files ) {
89
+ expect ( files . length ) . toBeGreaterThan ( 0 ) ;
90
+ done ( ) ;
91
+ } ) ;
92
+ } ) ;
93
+
94
+ it ( 'should replace each yourplugin string' , function ( done ) {
95
+ testUtils . findInFiles ( "yourplugin" , constants . SEED_COPY_LOCATION , function ( resultsCount ) {
96
+ expect ( resultsCount ) . toEqual ( 0 ) ;
97
+ done ( ) ;
98
+ } ) ;
99
+ } ) ;
100
+
101
+ it ( 'should replace each YourPlugin string' , function ( done ) {
102
+ testUtils . findInFiles ( "YourPlugin" , constants . SEED_COPY_LOCATION , function ( resultsCount ) {
103
+ expect ( resultsCount ) . toEqual ( 0 ) ;
104
+ done ( ) ;
105
+ } ) ;
106
+ } ) ;
107
+
108
+ it ( 'should replace each yourPlugin string' , function ( done ) {
109
+ testUtils . findInFiles ( "yourPlugin" , constants . SEED_COPY_LOCATION , function ( resultsCount ) {
110
+ expect ( resultsCount ) . toEqual ( 0 ) ;
111
+ done ( ) ;
112
+ } ) ;
113
+ } ) ;
114
+
115
+ it ( 'should replace each YourName string' , function ( done ) {
116
+ testUtils . findInFiles ( "YourName" , constants . SEED_COPY_LOCATION , function ( resultsCount ) {
117
+ expect ( resultsCount ) . toEqual ( 0 ) ;
118
+ done ( ) ;
119
+ } ) ;
120
+ } ) ;
121
+
122
+ it ( 'should replace each YourName string with the test github username' , function ( done ) {
123
+ testUtils . findInFiles ( constants . TEST_GITHUB_USERNAME , constants . SEED_COPY_LOCATION , function ( resultsCount ) {
124
+ // plugin author in the package json
125
+ expect ( resultsCount ) . toEqual ( 1 ) ;
126
+ done ( ) ;
127
+ } ) ;
128
+ } ) ;
129
+
130
+ it ( 'should replace each YourPlugin string with ThePlugin' , function ( done ) {
131
+ testUtils . findInFiles ( constants . TEST_PLUGIN_NAME , constants . SEED_COPY_LOCATION , function ( resultsCount ) {
132
+ expect ( resultsCount ) . toBeGreaterThan ( 0 ) ;
133
+ done ( ) ;
134
+ } ) ;
135
+ } ) ;
136
+
137
+ it ( 'should replace each nativescript-YourPlugin string with nativescript-ThePlugin' , function ( done ) {
138
+ testUtils . findInFiles ( "nativescript-" + constants . TEST_PLUGIN_NAME , constants . SEED_COPY_LOCATION , function ( resultsCount ) {
139
+ expect ( resultsCount ) . toBeGreaterThan ( 0 ) ;
140
+ done ( ) ;
141
+ } ) ;
142
+ } ) ;
143
+
144
+ it ( 'should prepare a working demo with passing tests' , function ( done ) {
145
+ var testsCommand = "cd " + constants . SEED_COPY_LOCATION + "/src && npm run test" ;
146
+ testsCommand += testUtils . isAndroid ( ) ? ".android" : ".ios" ;
147
+ exec ( testsCommand , function ( error , stdout , stderr ) {
148
+ expect ( error ) . toBeNull ( ) ;
149
+ done ( ) ;
150
+ } ) ;
151
+ } ) ;
152
+ } ) ;
0 commit comments