github.com/BarDweller/libpak@v0.0.0-20230630201634-8dd5cfc15ec9/sherpa/nodejs_test.go (about)

     1  /*
     2   * Copyright 2018-2020 the original author or authors.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      https://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package sherpa_test
    18  
    19  import (
    20  	"os"
    21  	"path/filepath"
    22  	"testing"
    23  
    24  	. "github.com/onsi/gomega"
    25  	"github.com/sclevine/spec"
    26  
    27  	"github.com/BarDweller/libpak/sherpa"
    28  )
    29  
    30  func testNodeJS(t *testing.T, context spec.G, it spec.S) {
    31  	var (
    32  		Expect = NewWithT(t).Expect
    33  
    34  		path string
    35  	)
    36  
    37  	it.Before(func() {
    38  		path = t.TempDir()
    39  	})
    40  
    41  	it("returns server.js if no package.json exists", func() {
    42  		Expect(sherpa.NodeJSMainModule(path)).To(Equal("server.js"))
    43  	})
    44  
    45  	it("returns server.js if package.json does not have a main entry", func() {
    46  		Expect(os.WriteFile(filepath.Join(path, "package.json"), []byte(`{}`), 0644)).To(Succeed())
    47  
    48  		Expect(sherpa.NodeJSMainModule(path)).To(Equal("server.js"))
    49  	})
    50  
    51  	it("returns main module", func() {
    52  		Expect(os.WriteFile(filepath.Join(path, "package.json"), []byte(`{ "main": "test-main" }`), 0644)).
    53  			To(Succeed())
    54  
    55  		Expect(sherpa.NodeJSMainModule(path)).To(Equal("test-main"))
    56  	})
    57  }