Skip to content
Open
Prev Previous commit
respect test-root option
  • Loading branch information
aduh95 committed Mar 2, 2022
commit 9f4470d9584cbb7c0bb1ee8c9190bf826ae663f3
25 changes: 12 additions & 13 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,16 @@ def get_module(name, path):
os.environ['NODE_OPTIONS'] = ''


def createKnowGlobalsJSON():
__dirname__ = dirname(__file__)
eslintConfigFile = join(__dirname__, '..', 'lib', '.eslintrc.yaml')
outputFile = join(__dirname__, '..', 'test', 'common', 'knownGlobals.json')
def createKnowGlobalsJSON(workspace, test_root):
eslintConfigFile = join(workspace, 'lib', '.eslintrc.yaml')
outputFile = join(test_root, 'common', 'knownGlobals.json')
searchLines = [
' no-restricted-globals:',
' node-core/prefer-primordials:',
]
isReadingGlobals = False
restrictedGlobalDeclaration = re.compile("^\s{4}- name:\s?([^#\s]+)")
closingSectionLine = re.compile("^\s{0,3}[^#\s]")
restrictedGlobalDeclaration = re.compile(r"^\s{4}- name:\s?([^#\s]+)")
closingSectionLine = re.compile(r"^\s{0,3}[^#\s]")
with open(eslintConfigFile, 'r') as eslintConfig, open(outputFile, 'w') as output:
output.write(u'["process"')
for line in eslintConfig.readlines():
Expand All @@ -116,15 +115,15 @@ def createKnowGlobalsJSON():
isReadingGlobals = True
output.write(u']')

def createKnowGlobalsJSONIfPossible():
def createKnowGlobalsJSONIfPossible(workspace, test_root):
try:
# Python 3
FileNotFoundError # noqa: F823
except NameError:
# Python 2
FileNotFoundError = IOError
try:
createKnowGlobalsJSON()
createKnowGlobalsJSON(workspace, test_root)
except FileNotFoundError:
# In the tarball, the .eslintrc.yaml file doesn't exist, and we cannot
# create the JSON file. However, in the tarball the JSON file has already
Expand Down Expand Up @@ -1614,10 +1613,6 @@ def Main():
parser.print_help()
return 1

if options.create_knownGlobal_json:
createKnowGlobalsJSON()
return 0

ch = logging.StreamHandler(sys.stdout)
logger.addHandler(ch)
logger.setLevel(logging.INFO)
Expand All @@ -1633,6 +1628,10 @@ def Main():
repositories = [TestRepository(join(test_root, name)) for name in suites]
repositories += [TestRepository(a) for a in options.suite]

if options.create_knownGlobal_json:
createKnowGlobalsJSON(workspace, test_root)
return 0

root = LiteralTestSuite(repositories, test_root)
paths = ArgsToTestPaths(test_root, args, suites)

Expand Down Expand Up @@ -1720,7 +1719,7 @@ def Main():
if has_crypto.stdout.rstrip() == 'undefined':
context.node_has_crypto = False

createKnowGlobalsJSONIfPossible()
createKnowGlobalsJSONIfPossible(workspace, test_root)

if options.cat:
visited = set()
Expand Down