aboutsummaryrefslogtreecommitdiff
path: root/test/apps/bun-install-lockfile-status.sh
blob: fc39a6dd6e81963332e0fb7877950018e81a962d (plain) (blame)
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
#!/usr/bin/env bash

set -euo pipefail

killall -9 $(basename $BUN_BIN) || echo ""

dir=$(mktemp -d)

cd $dir

$BUN_BIN add react

echo "node_modules" >.gitignore

git init && git add . && git commit -am "Initial commit"

$BUN_BIN install

ORIG_LOCKFILE="$($BUN_BIN pm hash-string)"

[[ -z $(git status --untracked-files=no --porcelain) ]] || {
    echo "ERR: Expected empty git status, got '$(git status --untracked-files=no --porcelain)'"
    exit 1
}

$BUN_BIN add react

NEW_LOCKFILE="$($BUN_BIN pm hash-string)"

diff <(echo "$ORIG_LOCKFILE") <(echo "$NEW_LOCKFILE") || {
    echo "ERR: Expected lockfile to be unchanged, got '$NEW_LOCKFILE'"
    exit 1
}

ORIG_HASH=$($BUN_BIN bun.lockb --hash)

$BUN_BIN remove react
$BUN_BIN add react

NEW_HASH=$($BUN_BIN bun.lockb --hash)

diff <(echo "$ORIG_HASH") <(echo "$NEW_HASH") || {
    echo "ERR: Expected hash to be unchanged, got '$NEW_HASH'"
    exit 1
}

echo '{ "dependencies": { "react": "17.0.2", "react-dom": "17.0.2" } }' >package.json

$BUN_BIN install

echo "var {version} = JSON.parse(require(\"fs\").readFileSync('./node_modules/react-dom/package.json', 'utf8')); if (version !== '17.0.2') {throw new Error('Unexpected react-dom version');}; " >index.js
$BUN_BIN run ./index.js

echo "var {version} = JSON.parse(require(\"fs\").readFileSync('./node_modules/react/package.json', 'utf8')); if (version !== '17.0.2') {throw new Error('Unexpected react version');}; " >index.js
$BUN_BIN run ./index.js

# This is just making sure that the JS was executed
realpath -e node_modules/react-dom >/dev/null || {
    echo "ERR: Expected react-dom to be installed"
    exit 1
}
realpath -e node_modules/react >/dev/null || {
    echo "ERR: Expected react to be installed"
    exit 1
}