Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Headlamp
Commits
ebbeecaa
Commit
ebbeecaa
authored
2 years ago
by
René Dudfield
Browse files
Options
Download
Email Patches
Plain Diff
headlamp-plugin: Convert published tests to js from bash
parent
bb3551c7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
Makefile
+1
-1
Makefile
plugins/headlamp-plugin/README.md
+3
-1
plugins/headlamp-plugin/README.md
plugins/headlamp-plugin/test-headlamp-plugin-published.js
+100
-0
plugins/headlamp-plugin/test-headlamp-plugin-published.js
plugins/headlamp-plugin/test-headlamp-plugin-published.sh
+0
-62
plugins/headlamp-plugin/test-headlamp-plugin-published.sh
plugins/headlamp-plugin/test-headlamp-plugin.js
+115
-0
plugins/headlamp-plugin/test-headlamp-plugin.js
plugins/headlamp-plugin/test-headlamp-plugin.sh
+0
-55
plugins/headlamp-plugin/test-headlamp-plugin.sh
with
219 additions
and
119 deletions
+219
-119
Makefile
+
1
-
1
View file @
ebbeecaa
...
...
@@ -78,7 +78,7 @@ frontend-test:
cd
frontend
&&
npm run
test
--
--coverage
plugins-test
:
cd
plugins/headlamp-plugin
&&
npm
install
&&
./test-headlamp-plugin.s
h
cd
plugins/headlamp-plugin
&&
npm
install
&&
./test-headlamp-plugin.
j
s
cd
plugins/headlamp-plugin
&&
./test-plugins-examples.sh
image
:
...
...
This diff is collapsed.
Click to expand it.
plugins/headlamp-plugin/README.md
+
3
-
1
View file @
ebbeecaa
...
...
@@ -34,7 +34,9 @@ Developing headlamp-plugin itself? Want to test your changes?
#### Integration tests
See test-headlamp-plugin.sh for some basic integration tests.
See test-headlamp-plugin.js for some basic integration tests.
See test-headlamp-plugin-published.js for testing published packages.
#### linking to use local version of headlamp-plugin
...
...
This diff is collapsed.
Click to expand it.
plugins/headlamp-plugin/test-headlamp-plugin-published.js
0 → 100755
+
100
-
0
View file @
ebbeecaa
#!/bin/env node
const
USAGE
=
`
This tests a published @kinvolk/headlamp-plugin package.
./test-headlamp-plugin-published.js 0.5.2
Assumes being run within the plugins/headlamp-plugin folder
`
;
function
testHeadlampPluginPublished
(
pluginVersion
)
{
run
(
`npm install @kinvolk/headlamp-plugin@
${
pluginVersion
}
`
);
run
(
'
npx @kinvolk/headlamp-plugin create headlamp-myfancy
'
);
curDir
=
path
.
join
(
tmpDir
,
'
headlamp-myfancy
'
);
// test headlamp-plugin build
run
(
'
npm run build
'
);
checkFileExists
(
path
.
join
(
curDir
,
'
dist
'
,
'
main.js
'
));
// test headlamp-plugin build folder
curDir
=
tmpDir
;
fs
.
rmSync
(
path
.
join
(
tmpDir
,
'
headlamp-myfancy
'
),
{
recursive
:
true
});
run
(
'
npx @kinvolk/headlamp-plugin create headlamp-myfancy
'
);
run
(
'
npx @kinvolk/headlamp-plugin build headlamp-myfancy
'
);
checkFileExists
(
path
.
join
(
curDir
,
'
headlamp-myfancy
'
,
'
dist
'
,
'
main.js
'
));
// test extraction works
run
(
'
npx @kinvolk/headlamp-plugin extract ./ .plugins
'
);
checkFileExists
(
path
.
join
(
curDir
,
'
.plugins
'
,
'
headlamp-myfancy
'
,
'
main.js
'
));
// test format command and that default code is formatted correctly
fs
.
rmSync
(
path
.
join
(
tmpDir
,
'
headlamp-myfancy
'
),
{
recursive
:
true
});
run
(
'
npx @kinvolk/headlamp-plugin create headlamp-myfancy
'
);
curDir
=
path
.
join
(
tmpDir
,
'
headlamp-myfancy
'
);
run
(
'
npm run format
'
);
// test lint command and default code is lint free
run
(
'
npm run lint
'
);
run
(
'
npm run lint-fix
'
);
// test type script error checks
run
(
'
npm run tsc
'
);
}
const
fs
=
require
(
'
fs
'
);
const
os
=
require
(
'
os
'
);
const
child_process
=
require
(
'
child_process
'
);
const
path
=
require
(
'
path
'
);
let
tmpDir
;
let
curDir
;
function
cleanup
()
{
console
.
log
(
`Cleaning up. Removing temp folder: "
${
tmpDir
}
"`
);
fs
.
rmSync
(
tmpDir
,
{
recursive
:
true
});
}
function
run
(
cmd
)
{
console
.
log
(
''
);
console
.
log
(
`Running cmd:
${
cmd
}
inside of cwd:
${
curDir
}
`
);
console
.
log
(
''
);
try
{
child_process
.
execSync
(
cmd
,
{
stdio
:
'
inherit
'
,
cwd
:
curDir
,
encoding
:
'
utf8
'
,
});
}
catch
(
e
)
{
console
.
error
(
`Error: Problem running "
${
cmd
}
" inside of "
${
curDir
}
"`
);
cleanup
();
process
.
exit
(
1
);
}
}
function
checkFileExists
(
fname
)
{
if
(
!
fs
.
existsSync
(
fname
))
{
console
.
error
(
`Error:
${
fname
}
does not exist.`
);
cleanup
();
process
.
exit
(
1
);
}
}
(
function
()
{
if
(
process
.
argv
[
1
].
includes
(
'
test-headlamp-plugin-published
'
))
{
const
pluginVersion
=
process
.
argv
[
2
];
if
(
pluginVersion
&&
process
.
argv
[
2
]
!==
'
--help
'
)
{
console
.
log
(
`Testing pluginVersion:
${
pluginVersion
}
`
);
}
else
{
console
.
log
(
''
);
console
.
log
(
'
pluginVersion as first argument required. Example: 0.5.2
'
);
console
.
log
(
USAGE
);
process
.
exit
(
1
);
}
tmpDir
=
fs
.
mkdtempSync
(
path
.
join
(
os
.
tmpdir
(),
'
tmp-test-headlamp-plugin
'
));
curDir
=
tmpDir
;
process
.
on
(
'
beforeExit
'
,
cleanup
);
testHeadlampPluginPublished
(
pluginVersion
);
}
})();
This diff is collapsed.
Click to expand it.
plugins/headlamp-plugin/test-headlamp-plugin-published.sh
deleted
100755 → 0
+
0
-
62
View file @
bb3551c7
#!/bin/sh
# Tests published @kinvolk/headlamp-plugin package.
#
# ./test-headlamp-plugin-published.sh 0.4.1-rc1
#
# Assumes being run within the plugins/headlamp-plugin folder
set
-e
set
-o
xtrace
plugin_version
=
$1
if
[
!
-z
$1
]
;
then
echo
"Testing plugin_version:
$plugin_version
"
else
echo
""
echo
"plugin_version as first argument required. Example: 0.4.1-rc1"
echo
""
exit
1
fi
# To make sure there's no package.json affecting things go to
cd
/tmp
TMPDIR
=
$(
mktemp
-d
)
echo
$TMPDIR
mkdir
-p
$TMPDIR
cd
$TMPDIR
# clean up tmp folder on exit
trap
"exit 1"
HUP INT PIPE QUIT TERM
trap
'echo Cleaning up tmp folder:"$TMPDIR" && rm -rf "$TMPDIR"'
EXIT
npm
install
@kinvolk/headlamp-plugin@
$plugin_version
npx @kinvolk/headlamp-plugin create headlamp-myfancy
cd
headlamp-myfancy
# test headlamp-plugin build
npm run build
stat
dist/main.js
# test headlamp-plugin build folder
cd
..
rm
-rf
headlamp-myfancy
npx @kinvolk/headlamp-plugin create headlamp-myfancy
npx @kinvolk/headlamp-plugin build headlamp-myfancy
stat
headlamp-myfancy/dist/main.js
# test extraction works
npx @kinvolk/headlamp-plugin extract ./ .plugins
stat
.plugins/headlamp-myfancy/main.js
# test format command and that default code is formatted correctly
rm
-rf
headlamp-myfancy
npx @kinvolk/headlamp-plugin create headlamp-myfancy
cd
headlamp-myfancy
npm run format
# test lint command and default code is lint free
npm run lint
npm run lint-fix
# test type script error checks
npm run tsc
This diff is collapsed.
Click to expand it.
plugins/headlamp-plugin/test-headlamp-plugin.js
0 → 100755
+
115
-
0
View file @
ebbeecaa
#!/bin/env node
const
USAGE
=
`
This tests unpublished @kinvolk/headlamp-plugin package in repo.
./test-headlamp-plugin.js
Assumes being run within the plugins/headlamp-plugin folder
`
;
const
PACKAGE_NAME
=
'
headlamp-myfancy
'
;
function
testHeadlampPlugin
()
{
// remove some temporary files.
cleanup
();
// Make a package file of headlamp-plugin we can test
run
(
'
npm install
'
);
run
(
'
npm run build
'
);
run
(
'
npm pack
'
);
const
packedFile
=
fs
.
readdirSync
(
'
.
'
)
.
filter
(
file
=>
file
.
match
(
'
kinvolk-headlamp-plugin-.*gz
'
))[
0
];
console
.
log
(
'
Packed headlamp-plugin package file:
'
,
packedFile
);
// Use "link" to test the repo version of the headlamp-plugin tool.
run
(
'
npm link
'
);
run
(
`node bin/headlamp-plugin.js create
${
PACKAGE_NAME
}
--link`
);
curDir
=
join
(
'
.
'
,
PACKAGE_NAME
);
run
(
`npm install
${
join
(
'
..
'
,
packedFile
)}
`
);
// test headlamp-plugin build
run
(
`node
${
join
(
'
..
'
,
'
bin
'
,
'
headlamp-plugin.js
'
)}
build`
);
checkFileExists
(
join
(
PACKAGE_NAME
,
'
dist
'
,
'
main.js
'
));
// test headlamp-plugin build folder
curDir
=
'
.
'
;
fs
.
rmSync
(
PACKAGE_NAME
,
{
recursive
:
true
});
run
(
`node bin/headlamp-plugin.js create
${
PACKAGE_NAME
}
--link`
);
curDir
=
PACKAGE_NAME
;
run
(
`npm install
${
join
(
'
..
'
,
packedFile
)}
`
);
curDir
=
'
.
'
;
run
(
`node bin/headlamp-plugin.js build
${
PACKAGE_NAME
}
`
);
checkFileExists
(
join
(
PACKAGE_NAME
,
'
dist
'
,
'
main.js
'
));
// test extraction works
run
(
`node bin/headlamp-plugin.js extract . .plugins`
);
checkFileExists
(
join
(
'
.plugins
'
,
PACKAGE_NAME
,
'
main.js
'
));
// test format command and that default code is formatted correctly
fs
.
rmSync
(
PACKAGE_NAME
,
{
recursive
:
true
});
run
(
`node bin/headlamp-plugin.js create
${
PACKAGE_NAME
}
--link`
);
curDir
=
PACKAGE_NAME
;
run
(
`npm install
${
join
(
'
..
'
,
packedFile
)}
`
);
run
(
'
npm run format
'
);
// test lint command and default code is lint free
run
(
'
npm run lint
'
);
run
(
'
npm run lint-fix
'
);
// test type script error checks
run
(
'
npm run tsc
'
);
}
const
fs
=
require
(
'
fs
'
);
const
child_process
=
require
(
'
child_process
'
);
const
path
=
require
(
'
path
'
);
const
join
=
path
.
join
;
let
curDir
;
function
cleanup
()
{
console
.
log
(
`Cleaning up. Removing temp files...`
);
fs
.
readdirSync
(
'
.
'
)
.
filter
(
file
=>
file
.
match
(
'
kinvolk-headlamp-plugin-.*gz
'
))
.
forEach
(
file
=>
fs
.
rmSync
(
file
));
const
foldersToRemove
=
[
path
.
join
(
'
.plugins
'
,
PACKAGE_NAME
),
PACKAGE_NAME
];
foldersToRemove
.
filter
(
folder
=>
fs
.
existsSync
(
folder
))
.
forEach
(
folder
=>
fs
.
rmSync
(
folder
,
{
recursive
:
true
}));
}
function
run
(
cmd
)
{
console
.
log
(
''
);
console
.
log
(
`Running cmd:
${
cmd
}
inside of cwd:
${
curDir
}
`
);
console
.
log
(
''
);
try
{
child_process
.
execSync
(
cmd
,
{
stdio
:
'
inherit
'
,
cwd
:
curDir
,
encoding
:
'
utf8
'
,
});
}
catch
(
e
)
{
console
.
error
(
`Error: Problem running "
${
cmd
}
" inside of "
${
curDir
}
"`
);
cleanup
();
process
.
exit
(
1
);
}
}
function
checkFileExists
(
fname
)
{
if
(
!
fs
.
existsSync
(
fname
))
{
console
.
error
(
`Error:
${
fname
}
does not exist.`
);
cleanup
();
process
.
exit
(
1
);
}
}
(
function
()
{
if
(
process
.
argv
[
1
].
includes
(
'
test-headlamp-plugin
'
))
{
console
.
log
(
USAGE
);
curDir
=
'
.
'
;
process
.
on
(
'
beforeExit
'
,
cleanup
);
testHeadlampPlugin
();
}
})();
This diff is collapsed.
Click to expand it.
plugins/headlamp-plugin/test-headlamp-plugin.sh
deleted
100755 → 0
+
0
-
55
View file @
bb3551c7
#!/bin/sh
# A simple test for the headlamp-plugin command line tool.
# Assumes being run within the plugins/headlamp-plugin folder
set
-e
set
-o
xtrace
rm
-rf
headlamp-myfancy
rm
-rf
.plugins/headlamp-myfancy
rm
-f
kinvolk-headlamp-plugin-
*
.tgz
npm
install
# Make a package file of headlamp-plugin we can test
npm run build
npm pack
# Use "link" to test the repo version of the headlamp-plugin tool.
npm
link
node bin/headlamp-plugin.js create headlamp-myfancy
--link
cd
headlamp-myfancy
npm
install
../kinvolk-headlamp-plugin-
*
.tgz
# test headlamp-plugin build
node ../bin/headlamp-plugin.js build
stat
dist/main.js
# test headlamp-plugin build folder
cd
..
rm
-rf
headlamp-myfancy
node bin/headlamp-plugin.js create headlamp-myfancy
--link
cd
headlamp-myfancy
npm
install
../kinvolk-headlamp-plugin-
*
.tgz
cd
..
node bin/headlamp-plugin.js build headlamp-myfancy
stat
headlamp-myfancy/dist/main.js
# test extraction works
node bin/headlamp-plugin.js extract ./ .plugins
stat
.plugins/headlamp-myfancy/main.js
# test format command and that default code is formatted correctly
rm
-rf
headlamp-myfancy
node bin/headlamp-plugin.js create headlamp-myfancy
--link
cd
headlamp-myfancy
npm
install
../kinvolk-headlamp-plugin-
*
.tgz
npm run format
# test lint command and default code is lint free
npm run lint
npm run lint-fix
# test type script error checks
npm run tsc
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help