main
 1// Copyright 2022 Google LLC
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     https://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import assert from 'node:assert'
16import { test, describe } from 'node:test'
17import { globby, fs, path } from '../build/index.js'
18
19const __dirname = path.dirname(new URL(import.meta.url).pathname)
20
21describe('extra', () => {
22  test('every file should have a license', async () => {
23    const copyright = await fs.readFile(
24      path.resolve(__dirname, 'fixtures/copyright.txt'),
25      'utf8'
26    )
27    const files = await globby(
28      ['**/*.{js,mjs,ts}', '!**/*polyfill.js', '!build'],
29      {
30        gitignore: true,
31        onlyFiles: true,
32        cwd: process.cwd(),
33        followSymbolicLinks: false,
34      }
35    )
36    for (const file of files) {
37      const content = await fs.readFile(file, 'utf8')
38      assert(
39        content.replace(/\d{4}/g, 'YEAR').includes(copyright),
40        `No license header in ${file}.`
41      )
42    }
43  })
44})